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:webservers 3 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: nginx 13 description: nginx repo 14 baseurl: http://nginx.org/packages/centos/7/$basearch/ 15 gpgcheck: no 16 enabled: 1 17 - name: Install nginx 18 yum: 19 name: nginx 20 state: latest 21 - name: Copy nginx configuration file 22 copy: 23 src: /ansible/nginx/conf/site.conf 24 dest: /etc/nginx/conf.d/site.conf 25 - name: Start nginx 26 service: 27 name: nginx 28 state: started 29 - name: Create wwwroot directory 30 file: 31 dest: /var/www/html 32 state: directory 33 - name: Create test page index.html 34 debug: #开启debug模式 35 msg: "123 {{ inventory_hostname }}" 36 tags: 37 - debug 38 39 执行 40 [root@test-1 bin]# ansible-playbook nginx_debug.yaml --tags debug 41 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