修改文件内容
按照下方所述,创建一个名为 /home/greg/ansible/issue.yml
的 playbook:
该 playbook 将在 所有清单主机
上运行
该 playbook 会将 /etc/issue
的内容替换为下方所示的一行文本:
在 dev
主机组中的主机上,这行文本显示为:Development
在 test
主机组中的主机上,这行文本显示为:Test
在 prod
主机组中的主机上,这行文本显示为:Production
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| [greg@control ansible]$ vim /home/greg/ansible/issue.yml --- - name: 修改文件内容 hosts: all tasks: - name: Copy using inline content copy: content: 'Development' dest: /etc/issue when: inventory_hostname in groups['dev'] - name: Copy using inline content copy: content: 'Test' dest: /etc/issue when: inventory_hostname in groups['test'] - name: Copy using inline content copy: content: 'Production' dest: /etc/issue when: inventory_hostname in groups['prod'] [greg@control ansible]$ ansible-playbook issue.yml [greg@control ansible]$ ansible dev -a 'cat /etc/issue' node1 | CHANGED | rc=0 >> Development [greg@control ansible]$ ansible test -a 'cat /etc/issue' node2 | CHANGED | rc=0 >> Test [greg@control ansible]$ ansible prod -a 'cat /etc/issue' node4 | CHANGED | rc=0 >> Production node3 | CHANGED | rc=0 >> Production
|