【 /home/ansible/playbook/nginx.yml 】
---
- hosts: webservers
vars:
worker_processes: 4
num_cups: 4
max_open_file: 65506
root: /data
remote_user: root
tasks:
- name: ensure nginx is at the latest version
yum: pkg=nginx state=latest
- name: write the nginx config file
template: src=/home/ansible/nginx/nginx2.conf dest=/etc/nginx/nginx.conf
notify:
- restart nginx
- name: ensure nginx is running
service: name=nginx state=started
handlers:
- name: restart nginx
service: name=nginx state=restarted
【 /home/ansible/nginx/nginx2.conf 】
user nginx
worker_processes {{ worker_processes }};
{% if num_cups == 2 %}
worker_cpu_affinity 01 10;
{% elif num_cups >= 4 %}
worker_cpu_affinity 1000 0100 0010 0001;
{% else %}
worker_cpu_affinity 1000 0100 0010 0001;
{% endif %}
worker_rlimit_nofile {{ max_open_file }};
… …
【 /etc/nginx/nginx.conf 】
user nginx
worker_processes 4;
worker_cpu_affinity 1000 0100 0010 0001;
worker_rlimit_nofile 65506;
… …
notify: - restart nginxhandlers: - name: restart nginx service: name=nginx state=restarted
Syntax:
ansible-playbook [options] PLAYBOOK.yml
options:
-C, --check: 测试模式, 不做任何更改, 而是尝试运行, 进行检查;-i INVENTORY, --inventory-file=INVENTORY specify inventory host path(default=/etc/ansible/hosts) or comma separated host list. 指定主机配置文件路径;
-u REMOTE_USER, --user=REMOTE_USER:手工指定远程执行playbook的系统用户;
--list-hosts: 输出匹配的主机列表, 不执行其他操作;
--list-tags : 列出所有可用的标签;
--list-tasks: 列出所有将要执行的任务;
-t TAGS, --tags=TAGS : 只运行tags标识的任务;
--skip-tags=SKIP-TAGS : 只运行tags没有标记的任务;
--syntax-check: 对剧本执行语法检查, 但是不执行;
错误信息