1、修改文件内容
按照下方所述,创建一个名为 /home/greg/ansible/issue.yml 的 playbook :
该 playbook 将在所有清单主机上运行
该 playbook 会将 /etc/issue 的内容替换为下方所示的一行文本:
在 dev 主机组中的主机上,这行文本显示 为:Development
在 test 主机组中的主机上,这行文本显示 为:Test
在 prod 主机组中的主机上,这行文本显示 为:Production
2、配置
编写playbook
vim /home/greg/ansible/issue.yml
---
- name:
hosts: all
tasks:
- name:
copy:
content: "Development"
dest: /etc/issue
when: inventory_hostname in groups['dev']
- name:
copy:
content: "Test"
dest: /etc/issue
when: inventory_hostname in groups['test']
- name:
copy:
content: "Production"
dest: /etc/issue
when: inventory_hostname in groups['prod']
运行
ansible-playbook issue.yml
3、检查