ansible - 如何调试缓慢的“ansible”(和“ansible-plabook”)?
问题描述
在管理具有特定角色的特定远程主机时,我面临着巨大的缓慢。
我已经追踪了缓慢的根源,发现对于一个非常具体的变量(为该特定主机定义并由该特定角色使用),ansible
构建ansible-playbook
它最多需要 30 秒,而对于其他变量,它只需要几秒钟。
我已经激活了详细模式并检查了日志文件,但除了ansible
有问题的变量在很长一段时间内完全静默(没有添加日志)之外,没有什么异常。
我的问题:
- 有没有办法调试
ansible
来找出我面临的问题的根本原因? - 任何人都可以对这种行为提出解释吗?
这是打印有问题的变量iptables
和另一个正常变量的结果ifcfg
:
time ansible fw1 -m debug -a "msg={{iptables}}" -vvvvvv
...
real 0m25.097s
user 0m26.564s
sys 0m0.272s
time ansible fw1 -m debug -a "msg={{ifcfg}}"
...
real 0m2.584s
user 0m2.636s
sys 0m0.097s
这是第一个命令的 ansible 日志:
2021-06-04 09:53:18,239 p=22258 u=yo n=ansible | ansible 2.9.21
config file = /path/to/ansible.cfg
configured module search path = [u'/path/to/.libs']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.17 (default, Feb 27 2021, 15:10:58) [GCC 7.5.0]
2021-06-04 09:53:18,239 p=22258 u=yo n=ansible | Using /path/to/ansible.cfg as config file
2021-06-04 09:53:18,239 p=22258 u=yo n=ansible | Reading vault password file: /path/to/ansible_vault_passwords
.
.
.
2021-06-04 09:53:18,472 p=22258 u=yo n=ansible | Decrypt of "/path/to/vault.yml" successful with secret=FileVaultSecret(filename='/path/to/ansible_vault_passwords') and vault_id=default
2021-06-04 09:53:44,250 p=22258 u=yo n=ansible | fw1 | SUCCESS => {
"msg": {
"allow": {
"ping": true,
"ssl": true
},
"forward": {
"enabled": true,
"http": {
"khlass_prd_bc_to_khlass_prd_app": {
"enabled": false,
"source": "11.5.40.0/24",
"target": "11.5.20.0/24"
},
"khlass_prd_dmz_to_khlass_prd_app": {
"enabled": false,
"source": "11.5.10.0/24",
"target": "11.5.20.0/24"
}
},
"https": {
"khlass_prd_bc_to_khlass_prd_app": {
"enabled": true,
"source": "11.5.40.0/24",
"target": "11.5.20.0/24"
},
"khlass_prd_dmz_to_khlass_prd_app": {
"enabled": true,
"source": "11.5.10.0/24",
"target": "11.5.20.0/24"
}
},
"mariadb": {
"khlass_prd_app_to_khlass_prd_db": {
"enabled": true,
"source": "11.5.20.0/24",
"target": "11.5.30.0/24"
}
},
"service": {
"khlass_prd_app_to_bc_api": {
"enabled": true,
"port": "8447",
"source": "11.5.20.0/24",
"target": "11.5.40.0/24"
}
}
},
"log": {
"filtered": true
},
"remove_firewalld": true
}
}
2021-06-04 09:53:44,250 p=22258 u=yo n=ansible | META: ran handlers
2021-06-04 09:53:44,250 p=22258 u=yo n=ansible | META: ran handlers
解决方案
在 的帮助下@Zeitounator
,我已经解决了这个问题。
该iptables
变量是具有多个级别的字典,我还有两个变量nets
,ifcfg
它们也是具有多个级别的字典。
的许多值iptables
是用来自的值设置的,这些值ifcfg
是使用来自的值设置的nets
。
我已经成功地设置了直接iptables
使用值的值nets
,现在的评估iptables
与其他变量一样快。
推荐阅读
- python - Xpath 只获取节点的第一个字符串
- java - 将配置文件添加到 classpath-java
- javascript - 仅显示一个标记以表示数组中多次出现相同的经纬度,但在 infowindow 中显示这些出现的数据
- apache-spark - Spark Scala:获取数据框行中非零列的计数
- python - Normalization by min-max & stand deviation method to only certain columns using Python or R
- javascript - uploadTask.snapshot.downloadURL 没有给出文件的下载 URL 作为响应
- navigation - 跳过导航链接...锚是否超出面包屑
- python - 提取文本文件的特定部分
- android - Unfold all variables in Android Studio debugger
- embedded - Getting wrong values in fs->win array after sending CMD17 command on sd card in check_fs function