1. ansible-playbook
1)ansible-playbook的语法检测1 [root@test-1 bin]# ansible-playbook --syntax-check nginx_tags.yaml 2 3 playbook: nginx_tags.yaml
2. ansible-debug打印实例
1)案例1 ---2 - hosts:webservers3 tasks:4 - debug:5 msg: { {group_names}} #打印ansible的host组6 - debug:7 msg: { {inventory_hostname}} #打印详细的host主机8 - debug:9 msg: { {ansible_hostname}} #配合gather_facts: yes 开启收集系统信息
3. ansible-debug使用案例
1) ansible-debug案例调试1 [root@test-1 bin]# vim nginx_debug.yaml 2 [root@test-1 bin]# cat nginx_debug.yaml 3 - hosts: web1 4 remote_user: root 5 gather_facts: no #禁止收集系统信息 6 vars: 7 hello: Ansible 8 9 tasks:10 - name: Add repo 11 yum_repository:12 name: nginx13 description: nginx repo14 baseurl: http://nginx.org/packages/centos/7/$basearch/15 gpgcheck: no16 enabled: 117 - name: Install nginx18 yum:19 name: nginx20 state: latest21 - name: Copy nginx configuration file22 copy:23 src: /ansible/nginx/conf/site.conf24 dest: /etc/nginx/conf.d/site.conf25 - name: Start nginx26 service:27 name: nginx28 state: started29 - name: Create wwwroot directory30 file:31 dest: /var/www/html32 state: directory33 - name: Create test page index.html34 debug: #开启debug模式35 msg: "123 { { inventory_hostname }}"36 tags:37 - debug38 39 执行40 [root@test-1 bin]# ansible-playbook nginx_debug.yaml --tags debug41 42 PLAY [web1] ************************************************************************************************************************************43 44 TASK [Create test page index.html] *************************************************************************************************************45 ok: [192.168.200.132] => {46 "msg": "123 192.168.200.132"47 }48 ok: [192.168.200.133] => {49 "msg": "123 192.168.200.133"50 }51 52 PLAY RECAP *************************************************************************************************************************************53 192.168.200.132 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 54 192.168.200.133 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0