ansible实战
# tree ansible/ansible/
├── group_vars
│ └── all
├── hosts
├── host_vars
│ └── 192.168.56.12
├── roles
│ └── nginx
│ ├── files
│ │ └── index.html
│ ├── handlers
│ │ └── main.yaml
│ ├── tasks
│ │ └── main.yaml
│ └── templates
│ └── nginx.conf.j2
├── site.retry
└── site.yaml
8 directories, 9 files
#
#####################################################################
# cat ansible/group_vars/all
version: 1.12.2
user: root
#
#####################################################################
# cat ansible/host_vars/192.168.56.12
worker_connections: 12400
#
#####################################################################
# catansible/roles/nginx/files/index.html
index
#
#####################################################################
# catansible/roles/nginx/handlers/main.yaml
[*]name: restart nginx service: name=nginxstate=restarted
#
#####################################################################
# catansible/roles/nginx/tasks/main.yaml
[*]name: install nginx yum: name=nginx-{{ version }} state=present
[*]name: copy templates template: src=nginx.conf.j2 dest=/etc/nginx/nginx.confowner=rootmode=644
notify: restart nginx
[*]name: copy index.html copy: src=index.html dest=/usr/share/nginx/html/index.html force=yes owner=rootmode=644
[*] name: start nginx
service: name=nginx state=started
#
#####################################################################
catansible/roles/nginx/templates/nginx.conf.j2
user {{ user }};
worker_processes {{ ansible_processor_cores }};
worker_connections {{ worker_connections }};
#####################################################################
# cat site.yaml
[*]name: Install nginx hosts: one
become: True
roles:
[*]nginx #
#####################################################################
ansible-playbook-i hostssite.yaml
页:
[1]