jwh5566
2017-10-07
python,ansible 2
---
- hosts: all
remote_user: ansible
tasks:
- name: print the ansible_os_family value
debug:
msg: '{{ ansible_os_family }}'
- name: ensure httpd is updated
yum:
name: httpd
state: latest
become: True
when: ansible_os_family == 'RedHat'
- name: ensure apache2 is updated
apt:
name: apache2
state: latest
become: True
when: ansible_os_family == 'Debian'
├── ansible.cfg # 帮助文件,指导ansible去哪找hosts和roles
├── hosts
├── master.yaml # 入口文件
├── playbooks
│ ├── firstrun.yaml # 一次性playbook
│ └── groups
│ ├── database.yaml # 这里表示tasks需要在那些group上面执行
│ └── webserver.yaml
└── roles
├── common
│ ├── files # 包含需要复制到远程的文件
│ ├── handlers # 包含tasks的触发器
│ ├── tasks
│ │ └── main.yaml # 这里是common角色需要执行的task
│ └── templates
│ └── motd # 这里是tasks需要的模板文件
├── database
└── webserver
playbook执行: ansible-playbook master.yaml
- hosts: localhost
tasks:
- name: Read the machine uptime
command: uptime -p
register: uptime
- name: Send the uptime via e-mail
mail:
host: mail.fale.io
username: [email protected]
password: PASSWORD
to: [email protected]
subject: Ansible-report
body: 'Local system uptime is {{ uptime.stdout }}.'