首页 > 其他分享 >ansible变量练习

ansible变量练习

时间:2022-10-30 19:36:01浏览次数:35  
标签:练习 变量 hwreport changed ansible student home txt

作业:
在ansible节点中新建/home/student/ansible/hwreport.empty的文件,文件内容为
hostname: inventoryhostname
mem: memory_in_MB
bios: BIOS_version
sda: disk_sda_size

创建一个名为 /home/student/ansible/hwreport.yml的 playbook,它将在所有受管节点上生成含有以下信息的输出文件 /root/hwreport.txt:

输出文件中的每一行含有一个 key=value 对。
您的 playbook 应当:
从 ansible节点中复制hwreport.empty文件到每台受控主机,并将它保存为/root/hwreport.txt
使用正确的值修改 /root/hwreport.txt
然后将/home/student/ansible/hwreport.yml这个playbook进行加密,加密的密码保存在/home/student/ansible/pass文件中,密码为abcdefg
执行该playbook,实现需求

[student@ansible ansible]$ vim hwreport.empty 

hostname: inventoryhostname
mem: memory_in_MB
bios: BIOS_version
sda: disk_sda_size


[student@ansible ansible]$ vim hwreport.yml

---
- name: hwreport
  hosts: all
  tasks:
    - name: copy hwreport.empty
      copy:
        src: /home/student/ansible/hwreport.empty
        dest: /root/hwreport.txt

    - name: inventoryhostname
      replace:
        path: /root/hwreport.txt
        regexp:  inventoryhostname
        replace: "{{ inventory_hostname }}"

    - name: men
      replace:
        path: /root/hwreport.txt
        regexp: memory_in_MB
        replace: "{{ ansible_memtotal_mb }}"

    - name: bios
      replace:
        path: /root/hwreport.txt
        regexp: BIOS_version
        replace: "{{ ansible_bios_version }}"

    - name: sda
      replace:
        path: /root/hwreport.txt
        regexp: disk_sda_size
        replace: "{{ ansible_devices.sda.size }}"


[student@ansible ansible]$ ansible-vault encrypt hwreport.yml
New Vault password: 
Confirm New Vault password: 
Encryption successful
[student@ansible ansible]$ echo abcdefg > /home/student/ansible/pass
[student@ansible ansible]$ ansible-playbook --vault-id /home/student/ansible/pass hwreport.yml 


[student@ansible ansible]$ ansible-playbook --vault-id /home/student/ansible/pass hwreport.yml 

PLAY [hwreport] *************************************************************************

TASK [Gathering Facts] ******************************************************************
ok: [node1]
ok: [node3]
ok: [node2]

TASK [copy hwreport.empty] **************************************************************
changed: [node2]
changed: [node1]
changed: [node3]

TASK [inventoryhostname] ****************************************************************
changed: [node1]
changed: [node2]
changed: [node3]

TASK [bios] *****************************************************************************
changed: [node2]
changed: [node3]
changed: [node1]

TASK [sda] ******************************************************************************
changed: [node2]
changed: [node1]
changed: [node3]

PLAY RECAP ******************************************************************************
node1                      : ok=5    changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
node2                      : ok=5    changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
node3                      : ok=5    changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   


标签:练习,变量,hwreport,changed,ansible,student,home,txt
From: https://www.cnblogs.com/loronoa/p/16841982.html

相关文章

  • while 练习
    importjava.util.Scanner;publicclassEext{ publicstaticvoidmain(String[]args){//某人有100.000元,每经过一次路口需要交费,规则如下//当现金在>......
  • 类变量(类对象变量)和实例对象变量详解
    类变量总结:第一:作为类对象的变量每次创建一个新的实例对象时,类对象变量就多一个引用指向它通过实例对象来修改类对象变量的取值,实际上是让实例对象的data指向了另外......
  • continue 练习
    importjava.util.Scanner;publicclassEext{ publicstaticvoidmain(String[]args){ladel1:for(intj=0;j<2;j++){ ladel2:......
  • 简单登录联练习
    importjava.util.Scanner;publicclassEext{ publicstaticvoidmain(String[]args){//实现登录验证,有三次机会,如果用户名为亚托克斯密码为777提示登录成......
  • Ansible 运维自动化
    Ansible概述Ansbile是一种IT自动化工具。它可以配置系统,部署软件以及协调更高级的IT任务,列如持续部署,滚动更新。Ansible适用于管理企业IT基础设施,从具有少数主机的小规模......
  • 0075-Go-变量
    环境Time2022-08-23Go1.19前言说明参考:https://gobyexample.com/variables目标使用Go语言变量的申明和使用变量。示例packagemainimport"fmt"funcma......
  • 解决windows下环境变量太长而无法添加的问题
    (39条消息)解决windows下环境变量太大的问题(终极!!可用)_河流儿的博客-CSDN博客_环境变量太大笔者电脑上装了一大堆软件,有一大堆的环境变量需要配置,而且有些软件,笔者也喜欢......
  • 求解Ax=0:主变量,特解
    第七讲:求解$Ax=0$,主变量,特解消元消元不会改变解的值。包括行消元和列消元,对矩阵$A\inR^{m\timesn}$进行行消元,就是使用矩阵的初等行变换,使得第$i$行第一个$\ne$0的......
  • #yyds干货盘点# LeetCode 腾讯精选练习 50 题:旋转链表
    题目:给你一个链表的头节点head,旋转链表,将链表每个节点向右移动 k 个位置。 示例1:输入:head=[1,2,3,4,5],k=2输出:[4,5,1,2,3]示例2:输入:head=[0,1,2],k=4输出......
  • #yyds干货盘点# LeetCode 腾讯精选练习 50 题:不同路径
    题目:一个机器人位于一个mxn 网格的左上角(起始点在下图中标记为“Start”)。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为“Finis......