ansible - 如何确认ansible任务不在运行列表中的原因
问题描述
当我执行剧本时,只会显示一个任务
playbook: test.yaml
play #1 (lab): lab TAGS: []
tasks:
Install pip TAGS: []
而当我执行剧本时,确实很正常
PLAY [lab] *****************************************************************************************************************************
TASK [Gathering Facts] *****************************************************************************************************************
ok: [my_ipaddress]
TASK [Install pip] *********************************************************************************************************************
ok: [my_ipaddress]
PLAY RECAP *****************************************************************************************************************************
my_ipaddress : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
并且在 /var/log/ansible.log 中看起来也与执行输出一样正常
所以问题是,我是否必须少做一些设置?为什么有一个任务不在执行列表中,或者有其他调试输出可以显示更详细的输出信息?
这是我的ansible配置
操作系统版本:Ubuntu 18.04.5 LTS ansible
版本:
ansible 2.9.12
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/primula/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/primula/.local/lib/python3.6/site-packages/ansible
executable location = /home/primula/.local/bin/ansible
python version = 3.6.9 (default, Jul 17 2020, 12:50:27) [GCC 8.4.0]
我的剧本:
---
- hosts: lab
roles:
- { role: apache2, become: yes }
- { role: pip, become: yes }
apache2角色配置
路径:/etc/ansible/roles/apache2/tasks/maim.yaml
---
- name: Install apache2
apt:
name: apache2
update_cache: yes
pip 角色配置
路径:/etc/ansible/roles/pip/tasks/main.yaml
---
- name: Install pip
apt:
name: python-pip
update_cache: yes
这是我的 ansible invotory & ansible.cfg invotory
[lab]
<ipaddress> ansible_ssh_user=<user_name> ansible_ssh_pass='<ssh_pass>' ansible_become_user=<root_user> ansible_become=true ansible_become_pass='<root_pass>'
ansible.cfg
[defaults]
private_key_file = /root/.ssh/id_rsa
roles_path = /etc/ansible/roles
inventory = /etc/ansible/hosts
timeout = 10
log_path = /var/log/ansible.log
deprecation_warnings = False
strategy = debug
any_errors_fatal = True
解决方案
使用时不在执行列表中的任务是与模块ansible-playbook --list-tasks your_playbook.yml
完成的事实收集相关的任务setup
这是一项隐式自动任务,默认情况下会为您游戏中的所有主机打开。如果是隐式的,则上述命令不会报告。
gather_facts
您可以使用play 关键字在游戏级别控制事实收集,例如
---
- name: Some play without facts gathering
hosts: my_group
gather_facts: false
tasks:
- name: dummy demo task
debug:
msg: I am dummy task
关于您关于更详细输出的问题,您可以ansible(-playbook)
使用开关打开详细模式-v(vv)
(v
s 越多,越详细)。
推荐阅读
- python - 在 PyQt5 中打开多个窗口时遇到问题
- ios12 - 子类 INObject?
- mysql - 在 MySQL 中使用 CASE 将值设置为 NULL 或空白
- c - 融合两个排序的数组
- php - 隐藏的mod仅针对某些路径重写到子文件夹
- php - PHP 不显示 HTML 输入
- android - 如果 gradle 中包含生命周期扩展,kotlin-android-extensions 将停止工作
- php - 使用 Digital Ocean 通过 IP 在 nginx 服务器上配置多站点
- c++ - 当我尝试从设备复制时,cudaMemcpy 返回 cudaErrorInvalidValue
- ruby-on-rails - 无法在 ubuntu for windows (wls) 上下载 heroku