ansible-playbook调试
2024-10-10 00:05:45
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
最新文章
- 【python】函数之内置函数
- 并查集(加权) LA 4487 Exclusive-OR
- 从Lumia退役看为什么WP走向没落
- codeforces 590C C. Three States(bfs+连通块之间的最短距离)
- Android查询:模拟键盘鼠标事件(adb shell 实现)
- mlock家族:锁定物理内存
- ios paper for facebook 使用第三方库
- 【POJ2761】【fhq treap】A Simple Problem with Integers
- NSSet与NSArray区别
- 笔记--cocos2d-x 3.0 环境搭建
- 微信web开发者工具使用
- Spring Boot + Dubbo 可运行的例子源码-实现服务注册和远程调用
- ORALCE PL/SQL学习笔记
- C# join子句
- 文件操作(File类等)API摘要
- oracle的PDB启动
- 使用scp命令在多个Linux系统间进行文件复制
- Mac键盘按键符号
- mui---取消掉默认加载框
- Cracking The Coding Interview3.3