playbooks 是一种简单的配置管理系统与多机器部署系统的基础。与现有的其他系统有不同之处,且非常适合于复杂应用的批量部署
Playbooks 的格式是YAML,语法做到最小化

这里讲述的是使用ansible-playbooks的roles安装Nginx应用

结构目录

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#结构目录
[root@Ansible ansible]# tree /etc/ansible/
/etc/ansible/
├── ansible.cfg
├── hosts
├── roles
│   ├── source_nginx
│   │   ├── files
│   │   │   ├── echo-nginx-module-0.59.tar.gz
│   │   │   ├── gperftools-2.0.zip
│   │   │   ├── nginx-1.11.7.tar.gz
│   │   │   ├── nginx_tcp_proxy_module_nginx1.11.7.zip
│   │   │   ├── nginx-upstream-jvm-route-nginx1.11.7.zip
│   │   │   ├── ngx_cache_purge-2.3.tar.gz
│   │   │   ├── openssl-1.1.0e.tar.gz
│   │   │   ├── pcre-8.40.zip
│   │   │   ├── yum.repo
│   │   │   └── zlib-1.2.11.tar.gz
│   │   ├── handlers
│   │   │   └── main.yml
│   │   ├── tasks
│   │   │   └── main.yml
│   │   ├── templates
│   │   │   ├── comm.conf.j2
│   │   │   ├── etc_init.d_nginx.txt
│   │   │   ├── fastcgi.conf.j2
│   │   │   ├── nginx.conf.j2
│   │   │   ├── proxy.conf.j2
│   │   │   └── static.conf.j2
│   │   └── vars
│   │   └── main.yml
│   └── yum_nginx
│   ├── files
│   │   ├── comm.conf.j2
│   │   ├── fastcgi.conf.j2
│   │   ├── nginx.conf.j2
│   │   ├── proxy.conf.j2
│   │   ├── static.conf.j2
│   │   └── yum.repo
│   ├── handlers
│   │   └── main.yml
│   ├── tasks
│   │   └── main.yml
│   ├── templates
│   └── vars
│   └── main.yml
└── site.yml
13 directories, 31 files
[root@Ansible ansible]#

Ansible之Yum安装Nginx

环境:
   ansible 2.2.1.0
   Centos 6.6
   Nginx 1.11.7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#结构目录
[root@Ansible ansible]# tree roles/yum_nginx/
roles/yum_nginx/
├── files
│   ├── comm.conf.j2
│   ├── fastcgi.conf.j2
│   ├── nginx.conf.j2
│   ├── proxy.conf.j2
│   ├── static.conf.j2
│   └── yum.repo
├── handlers
│   └── main.yml
├── tasks
│   └── main.yml
├── templates
└── vars
└── main.yml
5 directories, 9 files
[root@Ansible ansible]#

1
2
3
4
5
6
7
8
#入口文件
[root@Ansible ~]# cd /etc/ansible/
[root@Ansible ansible]# cat site.yml
- hosts: test_hosts
user: root
roles:
- yum_nginx
[root@Ansible ansible]#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#变量
[root@Ansible ansible]# cat roles/yum_nginx/vars/main.yml
error_log_path: /var/log/nginx/error.log
error_log_level: warn
access_log_path: /var/log/nginx/access.log
nginx_pid_path: /var/run/nginx.pid
worker_connections_size: 10240
keys_zone: one_cache
keys_zone_size: 1024m
inactive_day: 1d
max_size: 10g
proxy_cache_path: /var/proxy_cache
nginx_log_path: /var/log/nginx
[root@Ansible ansible]#
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#tasks文件
[root@Ansible ansible]# cat roles/yum_nginx/tasks/main.yml
- name: disabled iptables
service: name=iptables state=stopped
- name: Set the selinux value to Permissive
shell: setenforce 0
- name: Install libselinux-python package
yum: name=libselinux-python state=installed
- name: Check whether yum.repo file exist
shell: ls /etc/yum.repos.d/yum.repo
register: result
ignore_errors: True
- name: Copy yum.repo file
copy: src=yum.repo dest=/etc/yum.repos.d/ mode=0644 owner=root group=root
when: result|failed
- name: Rebuild the yum cache
shell: yum clean all && yum makecache
when: result|failed
- name: Install nginx package
yum: name=nginx state={{item.state}}
with_items:
- state: "absent"
- state: "installed"
- name: set nginx parameter
set_fact: worker_processes="{{ansible_processor_cores}}"
- name: Configure some files
template: src={{item.src}} dest={{item.dest}} owner=nginx group=nginx mode=0644
with_items:
- src: "files/nginx.conf.j2"
dest: "/etc/nginx/nginx.conf"
- src: "files/proxy.conf.j2"
dest: "/etc/nginx/conf.d/proxy.conf"
- src: "files/comm.conf.j2"
dest: "/etc/nginx/conf.d/comm.conf"
- src: "files/static.conf.j2"
dest: "/etc/nginx/conf.d/static.conf"
- src: "files/fastcgi.conf.j2"
dest: "/etc/nginx/conf.d/fastcgi.conf"
- name: Create some directory
file: path={{item.path}} state=directory owner=nginx group=nginx mode=0755
with_items:
- path: "{{proxy_cache_path}}/temp"
- path: "{{proxy_cache_path}}/cache"
- path: "{{nginx_log_path}}"
notify: restart nginx
[root@Ansible ansible]#
1
2
3
4
5
#handlers
[root@Ansible ansible]# cat roles/yum_nginx/handlers/main.yml
- name: restart nginx
service: name=nginx state=restarted enabled=yes
[root@Ansible ansible]#
1
2
3
4
#files文件
[root@Ansible ansible]# ls roles/yum_nginx/files/
comm.conf.j2 fastcgi.conf.j2 nginx.conf.j2 proxy.conf.j2 static.conf.j2 yum.repo
[root@Ansible ansible]#
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#执行结果
[root@Ansible ~]# ansible-playbook /etc/ansible/site.yml
PLAY [test_hosts] **************************************************************
TASK [setup] *******************************************************************
ok: [192.168.31.110]
TASK [yum_nginx : disabled iptables] *******************************************
changed: [192.168.31.110]
TASK [yum_nginx : Set the selinux value to Permissive] *************************
changed: [192.168.31.110]
TASK [yum_nginx : Install libselinux-python package] ***************************
changed: [192.168.31.110]
TASK [yum_nginx : Check whether yum.repo file exist] ***************************
fatal: [192.168.31.110]: FAILED! => {"changed": true, "cmd": "ls /etc/yum.repos.d/yum.repo", "delta": "0:00:00.004099", "end": "2017-03-19 20:49:37.832598", "failed": true, "rc": 2, "start": "2017-03-19 20:49:37.828499", "stderr": "ls: cannot access /etc/yum.repos.d/yum.repo: No such file or directory", "stdout": "", "stdout_lines": [], "warnings": []}
...ignoring
TASK [yum_nginx : Copy yum.repo file] ******************************************
changed: [192.168.31.110]
TASK [yum_nginx : Rebuild the yum cache] ***************************************
changed: [192.168.31.110]
[WARNING]: Consider using yum module rather than running yum
TASK [yum_nginx : Install nginx package] ***************************************
ok: [192.168.31.110] => (item={u'state': u'absent'})
changed: [192.168.31.110] => (item={u'state': u'installed'})
TASK [yum_nginx : set nginx parameter] *****************************************
ok: [192.168.31.110]
TASK [yum_nginx : Configure some files] ****************************************
changed: [192.168.31.110] => (item={u'dest': u'/etc/nginx/nginx.conf', u'src': u'files/nginx.conf.j2'})
changed: [192.168.31.110] => (item={u'dest': u'/etc/nginx/conf.d/proxy.conf', u'src': u'files/proxy.conf.j2'})
changed: [192.168.31.110] => (item={u'dest': u'/etc/nginx/conf.d/comm.conf', u'src': u'files/comm.conf.j2'})
changed: [192.168.31.110] => (item={u'dest': u'/etc/nginx/conf.d/static.conf', u'src': u'files/static.conf.j2'})
changed: [192.168.31.110] => (item={u'dest': u'/etc/nginx/conf.d/fastcgi.conf', u'src': u'files/fastcgi.conf.j2'})
TASK [yum_nginx : Create some directory] ***************************************
changed: [192.168.31.110] => (item={u'path': u'/var/proxy_cache/temp'})
changed: [192.168.31.110] => (item={u'path': u'/var/proxy_cache/cache'})
changed: [192.168.31.110] => (item={u'path': u'/var/log/nginx'})
RUNNING HANDLER [yum_nginx : restart nginx] ************************************
changed: [192.168.31.110]
PLAY RECAP *********************************************************************
192.168.31.110 : ok=12 changed=10 unreachable=0 failed=0
[root@Ansible ~]#

image
image

Ansible之源码安装Nginx

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
#结构目录
[root@Ansible ansible]# tree roles/source_nginx/
roles/source_nginx/
├── files
│   ├── echo-nginx-module-0.59.tar.gz
│   ├── gperftools-2.0.zip
│   ├── nginx-1.11.7.tar.gz
│   ├── nginx_tcp_proxy_module_nginx1.11.7.zip
│   ├── nginx-upstream-jvm-route-nginx1.11.7.zip
│   ├── ngx_cache_purge-2.3.tar.gz
│   ├── openssl-1.1.0e.tar.gz
│   ├── pcre-8.40.zip
│   ├── yum.repo
│   └── zlib-1.2.11.tar.gz
├── handlers
│   └── main.yml
├── tasks
│   └── main.yml
├── templates
│   ├── comm.conf.j2
│   ├── etc_init.d_nginx.txt
│   ├── fastcgi.conf.j2
│   ├── nginx.conf.j2
│   ├── proxy.conf.j2
│   └── static.conf.j2
└── vars
└── main.yml
5 directories, 19 files
[root@Ansible ansible]#
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
#变量
[root@Ansible ansible]# cat roles/source_nginx/vars/main.yml
nginx_path: /usr/local/nginx-1.11.7/sbin/nginx
nginx_conf_file: /usr/local/nginx-1.11.7/conf/nginx.conf
nginx_conf_dir: /usr/local/nginx-1.11.7/conf
error_log_path: /var/log/nginx/error.log
error_log_level: warn
access_log_path: /var/log/nginx/access.log
nginx_pid_path: /var/run/nginx.pid
worker_connections_size: 1024
google_perftools_path: /var/tmp/nginx_profile
proxy_temp_path: /var/proxy_cache/temp
proxy_cache_path: /var/proxy_cache/cache
keys_zone: one_cache
keys_zone_size: 1024m
inactive_day: 1d
max_size: 10g
rewrite_path: http://www.qq.com
access_zabbix_log_path: /var/log/zabbix/access.log
error_zabbix_log_path: /var/log/zabbix/error.log
remote_download_path: /tmp/download
nginx_install_path: /usr/local/nginx-1.11.7
[root@Ansible ansible]#
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#tasks
[root@Ansible ansible]# cat roles/source_nginx/tasks/main.yml
- name: disabled iptables
shell: /etc/init.d/iptables stop
- name: Set the selinux value to Permissive
shell: setenforce 0
- name: Create download directory
file: path={{remote_download_path}} mode=0755 state=directory
- name: Install the some tools
yum: name={{item.name}} state=installed
with_items:
- name: unzip
- name: zip
- name: tar
- name: libselinux-python
- name: download some source packages
get_url: url={{item.url}} dest={{remote_download_path}} validate_certs={{item.validate_certs|default("yes")}}
with_items:
- url: "https://ftp.pcre.org/pub/pcre/pcre-8.40.zip"
validate_certs: "no"
- url: "http://nginx.org/download/nginx-1.11.7.tar.gz"
- name: unarchive some source packages
unarchive: src={{item.src}} dest={{remote_download_path}} remote_src={{item.remote_src|default("no")}}
with_items:
- src: "{{remote_download_path}}/nginx-1.11.7.tar.gz"
remote_src: "yes"
- src: "{{remote_download_path}}/pcre-8.40.zip"
remote_src: "yes"
- src: "files/zlib-1.2.11.tar.gz"
- src: "files/openssl-1.1.0e.tar.gz"
- src: "files/gperftools-2.0.zip"
- src: "files/echo-nginx-module-0.59.tar.gz"
- src: "files/nginx-upstream-jvm-route-nginx1.11.7.zip"
- src: "files/ngx_cache_purge-2.3.tar.gz"
- name: Check whether nginx users exist
shell: id nginx
register: result
ignore_errors: True
- name: The nginx user does not exist, so we need to create it.[The nginx user's password is 123456]
user: name=nginx createhome=yes home=/home/nginx shell=/bin/bash password="$1$K28XAyId$YUKHvYzbbO9C8RkzGIzNo1" state=present
when: result|failed
- name: Install the pcre-8.40 source package
shell: cd {{remote_download_path}}/pcre-8.40/ && sh ./configure && make && make install
- name: Install the zlib-1.2.11 source package
shell: cd {{remote_download_path}}/zlib-1.2.11/ && sh ./configure && make && make install
- name: Install the openssl-1.1.0e source package
shell: cd {{remote_download_path}}/openssl-1.1.0e/ && sh ./config && make && make install
- name: Install the some devel packages
yum: name={{item.rpm}} state=installed
with_items:
- rpm: "openssl-devel"
- rpm: "pcre-devel"
- rpm: "zlib-devel"
- rpm: "gcc"
- rpm: "gcc-c++"
- rpm: "make"
- rpm: "perl"
- rpm: "perl-devel"
- rpm: "perl-ExtUtils-Embed"
- name: Install the gperftools-2.0 source package
shell: cd {{remote_download_path}}/gperftools-2.0/ && sh ./configure --enable-frame-pointers && make && make install && echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf && ldconfig
- name: Install patch package
yum: name=patch state=installed
- name: Play nginx-upstream-jvm-route patche
shell: cd {{remote_download_path}}/nginx-1.11.7/ && patch -p0 < ../nginx-upstream-jvm-route/jvm_route.patch
- name: Install the Nginx package
shell: cd {{remote_download_path}}/nginx-1.11.7/ && sh ./configure --prefix={{nginx_install_path}} --user=nginx --group=nginx --with-http_gzip_static_module --with-http_stub_status_module --with-google_perftools_module --add-module=../echo-nginx-module-0.59 --add-module=../nginx-upstream-jvm-route --with-pcre=../pcre-8.40 --without-http_ssi_module --without-http_autoindex_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --add-module=../ngx_cache_purge-2.3 --with-http_ssl_module --with-openssl=../openssl-1.1.0e --with-stream --with-http_mp4_module && make && make install
- name: Create some directory
file: path={{item.path}} state=directory mode={{item.mode|default("0755")}} owner=nginx group=nginx
with_items:
- path: "/tmp/tcmalloc"
mode: "0777"
- path: "/var/proxy_cache/temp"
- path: "/var/proxy_cache/cache"
- path: "/var/log/nginx"
- path: "{{nginx_conf_dir}}/vhosts"
- name: set nginx parameter
set_fact: worker_processes="{{ansible_processor_cores}}"
- name: Copy same files
template: src={{item.src}} dest={{item.dest}} owner=nginx group=nginx mode={{item.mode|default("0644")}}
with_items:
- src: "templates/etc_init.d_nginx.txt"
dest: "/etc/init.d/nginx"
mode: "0755"
- src: "templates/nginx.conf.j2"
dest: "{{nginx_conf_dir}}/nginx.conf"
- src: "templates/proxy.conf.j2"
dest: "{{nginx_conf_dir}}/vhosts/proxy.conf"
- src: "templates/comm.conf.j2"
dest: "{{nginx_conf_dir}}/vhosts/comm.conf"
- src: "templates/static.conf.j2"
dest: "{{nginx_conf_dir}}/vhosts/static.conf"
- src: "templates/fastcgi.conf.j2"
dest: "{{nginx_conf_dir}}/vhosts/fastcgi.conf"
notify: restart nginx
[root@Ansible ansible]#
1
2
3
4
5
#handlers
[root@Ansible ansible]# cat roles/source_nginx/handlers/main.yml
- name: restart nginx
service: name=nginx state=restarted enabled=yes
[root@Ansible ansible]#
1
2
3
4
5
6
#files
[root@Ansible ansible]# ls roles/source_nginx/files/
echo-nginx-module-0.59.tar.gz nginx_tcp_proxy_module_nginx1.11.7.zip openssl-1.1.0e.tar.gz zlib-1.2.11.tar.gz
gperftools-2.0.zip nginx-upstream-jvm-route-nginx1.11.7.zip pcre-8.40.zip
nginx-1.11.7.tar.gz ngx_cache_purge-2.3.tar.gz yum.repo
[root@Ansible ansible]#
1
2
3
4
#templates
[root@Ansible ansible]# ls roles/source_nginx/templates/
comm.conf.j2 etc_init.d_nginx.txt fastcgi.conf.j2 nginx.conf.j2 proxy.conf.j2 static.conf.j2
[root@Ansible ansible]#
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#执行结果
[root@Ansible ~]# ansible-playbook /etc/ansible/site.yml
PLAY [test_hosts] **************************************************************
TASK [setup] *******************************************************************
ok: [192.168.31.110]
TASK [source_nginx : disabled iptables] ****************************************
changed: [192.168.31.110]
TASK [source_nginx : Set the selinux value to Permissive] **********************
changed: [192.168.31.110]
TASK [source_nginx : Create download directory] ********************************
changed: [192.168.31.110]
TASK [source_nginx : Install the some tools] ***********************************
changed: [192.168.31.110] => (item={u'name': u'unzip'})
changed: [192.168.31.110] => (item={u'name': u'zip'})
ok: [192.168.31.110] => (item={u'name': u'tar'})
changed: [192.168.31.110] => (item={u'name': u'libselinux-python'})
TASK [source_nginx : download some source packages] ****************************
changed: [192.168.31.110] => (item={u'url': u'https://ftp.pcre.org/pub/pcre/pcre-8.40.zip', u'validate_certs': u'no'})
changed: [192.168.31.110] => (item={u'url': u'http://nginx.org/download/nginx-1.11.7.tar.gz'})
TASK [source_nginx : unarchive some source packages] ***************************
changed: [192.168.31.110] => (item={u'src': u'/tmp/download/nginx-1.11.7.tar.gz', u'remote_src': u'yes'})
changed: [192.168.31.110] => (item={u'src': u'/tmp/download/pcre-8.40.zip', u'remote_src': u'yes'})
changed: [192.168.31.110] => (item={u'src': u'files/zlib-1.2.11.tar.gz'})
changed: [192.168.31.110] => (item={u'src': u'files/openssl-1.1.0e.tar.gz'})
changed: [192.168.31.110] => (item={u'src': u'files/gperftools-2.0.zip'})
changed: [192.168.31.110] => (item={u'src': u'files/echo-nginx-module-0.59.tar.gz'})
changed: [192.168.31.110] => (item={u'src': u'files/nginx-upstream-jvm-route-nginx1.11.7.zip'})
changed: [192.168.31.110] => (item={u'src': u'files/ngx_cache_purge-2.3.tar.gz'})
TASK [source_nginx : Check whether nginx users exist] **************************
fatal: [192.168.31.110]: FAILED! => {"changed": true, "cmd": "id nginx", "delta": "0:00:00.003932", "end": "2017-03-19 20:29:56.963783", "failed": true, "rc": 1, "start": "2017-03-19 20:29:56.959851", "stderr": "id: nginx: No such user", "stdout": "", "stdout_lines": [], "warnings": []}
...ignoring
TASK [source_nginx : The nginx user does not exist, so we need to create it.[The nginx user's password is 123456]] ***
changed: [192.168.31.110]
TASK [source_nginx : Install the pcre-8.40 source package] *********************
changed: [192.168.31.110]
TASK [source_nginx : Install the zlib-1.2.11 source package] *******************
changed: [192.168.31.110]
TASK [source_nginx : Install the openssl-1.1.0e source package] ****************
changed: [192.168.31.110]
TASK [source_nginx : Install the some devel packages] **************************
changed: [192.168.31.110] => (item={u'rpm': u'openssl-devel'})
changed: [192.168.31.110] => (item={u'rpm': u'pcre-devel'})
ok: [192.168.31.110] => (item={u'rpm': u'zlib-devel'})
ok: [192.168.31.110] => (item={u'rpm': u'gcc'})
ok: [192.168.31.110] => (item={u'rpm': u'gcc-c++'})
ok: [192.168.31.110] => (item={u'rpm': u'make'})
ok: [192.168.31.110] => (item={u'rpm': u'perl'})
changed: [192.168.31.110] => (item={u'rpm': u'perl-devel'})
changed: [192.168.31.110] => (item={u'rpm': u'perl-ExtUtils-Embed'})
TASK [source_nginx : Install the gperftools-2.0 source package] ****************
changed: [192.168.31.110]
TASK [source_nginx : Install patch package] ************************************
changed: [192.168.31.110]
TASK [source_nginx : Play nginx-upstream-jvm-route patche] *********************
changed: [192.168.31.110]
TASK [source_nginx : Install the Nginx package] ********************************
changed: [192.168.31.110]
TASK [source_nginx : Create some directory] ************************************
changed: [192.168.31.110] => (item={u'path': u'/tmp/tcmalloc', u'mode': u'0777'})
changed: [192.168.31.110] => (item={u'path': u'/var/proxy_cache/temp'})
changed: [192.168.31.110] => (item={u'path': u'/var/proxy_cache/cache'})
changed: [192.168.31.110] => (item={u'path': u'/var/log/nginx'})
changed: [192.168.31.110] => (item={u'path': u'/usr/local/nginx-1.11.7/conf/vhosts'})
TASK [source_nginx : set nginx parameter] **************************************
ok: [192.168.31.110]
TASK [source_nginx : Copy same files] ******************************************
changed: [192.168.31.110] => (item={u'dest': u'/etc/init.d/nginx', u'src': u'templates/etc_init.d_nginx.txt', u'mode': u'0755'})
changed: [192.168.31.110] => (item={u'dest': u'/usr/local/nginx-1.11.7/conf/nginx.conf', u'src': u'templates/nginx.conf.j2'})
changed: [192.168.31.110] => (item={u'dest': u'/usr/local/nginx-1.11.7/conf/vhosts/proxy.conf', u'src': u'templates/proxy.conf.j2'})
changed: [192.168.31.110] => (item={u'dest': u'/usr/local/nginx-1.11.7/conf/vhosts/comm.conf', u'src': u'templates/comm.conf.j2'})
changed: [192.168.31.110] => (item={u'dest': u'/usr/local/nginx-1.11.7/conf/vhosts/static.conf', u'src': u'templates/static.conf.j2'})
changed: [192.168.31.110] => (item={u'dest': u'/usr/local/nginx-1.11.7/conf/vhosts/fastcgi.conf', u'src': u'templates/fastcgi.conf.j2'})
RUNNING HANDLER [source_nginx : restart nginx] *********************************
changed: [192.168.31.110]
PLAY RECAP *********************************************************************
192.168.31.110 : ok=21 changed=19 unreachable=0 failed=0
[root@Ansible ~]#
1
2
3
4
5
[root@Ansible ~]# ansible test_hosts -a '/etc/init.d/nginx status'
192.168.31.110 | SUCCESS | rc=0 >>
nginx (pid 76973) is running...
[root@Ansible ~]#

image
image

附件:ansible_install_nginx1.11.7.tar.gz


本文出自”Jack Wang Blog”:http://www.yfshare.vip/2017/03/11/Ansible-Playbooks之安装Nginx/