1.判断语句when
[root@manager ansible_tasks]
- hosts: webservers
tasks:
- name: Installed HTTP Server
yum:
name: httpd
state: present
when: (ansible_distribution == "CentOS")
- name: Installed HTTP Server
yum:
name: httpd2
state: present
when: (ansible_distribution == "Ubuntu")
[root@manager ansible_tasks]
[root@manager ansible_tasks]
- hosts: all
tasks:
- name: Installed Nginx Web Server
yum:
name: nginx
state: present
when: ( ansible_hostname is match("web*"))
[root@manager ansible_tasks]
2.循环语句loop|with_items
2.1一个tasks安装多个软件 (列表)
[root@manager ansible_tasks]
- hosts: webservers
tasks:
- name: Install Rpm All
yum:
name: "{
{ item }}"
state: present
loop:
- httpd
- httpd-tools