—
– hosts: all
remote_user: root
vars:
ports:
-81
-82
-83
vars:
ports:
– listen_port: 81
– listen_port: 82
– listen_port: 83
vars:
ports:
– web1:
port: 81
#name: web1.mnixiao.com
rootdir: /root/web1
– web2:
port: 82
name: web2.mnixiao.com
rootdir: /root/web2
– web3:
port: 83
#name: web3.mnixiao.com
rootdir: /root/web3
vars_files:
– vars.yml
vars:
– haha:
xixi: ni111
hehe: xiao222
– pipi:
jj: dajj
qq: xiaoqq
tasks:
– name: creat some file
group: name={{ item }}
when: ansible_distribution_major_version == “7”
with_items:
– g1
– g2
– g3
– name: add some users
user: name={{ item.name }} group={{ item.group }} state=present
with_items:
– { name: ‘user1’, group: ‘g1’}
– { name: ‘user2’, group: ‘g2’}
– { name: ‘user3’, group: ‘g3’}
– name: install httpd package
yum: name=httpd
tags: anzhuanghttpd
– name: copy template for centos7
template: src=nginx.conf7.j2 dest=/etc/nginx/nginx.conf
when: ansible_distribution_major_version == “7”
(when: ansible_os_family == “RedHat”)
notify:
– Restart Nginx
– Check Nginx Process
– name: copy template for centos7
Module: Args || /bin/true
或
Module: Args
ignore_errors: True
– name: test connection
ping:
remote_user: magedu
sudo: yes
sudo_user: wang
handlers:
– name: Restart Nginx
service: name=nginx state=restarted enabled=yes
– name: Check Nginx process
shell: killall -0 nginx > /tmp/nginx.log
本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/104172