我在Ansible 2.8.6中使用AWX 8.0.0.0。我在Inventory script
下的AWX中添加了一个新脚本:
#!/bin/sh
curl -s GET "https://myserver/inventory" -H "accept: application/json" --user $INVENTORY_CREDENTIALS &> /dev/stdout
#eof
此脚本运行良好,当我在ansible-playbook -i inventory.sh ...
本地使用它时,该变量实际上已被替换-我可以在服务器上看到请求。结果是一个JSON库存(数据来自后端中的数据库)。格式正确(生成)
当我将自定义脚本添加为清单并运行同步作业时,该作业“成功”-但清单为空。当我查看作业日志时,它显示以下输出:
1.779 INFO Updating inventory 3: test
2.072 INFO Reading Ansible inventory source: /tmp/awx_1302_0cicirws/tmpsgddb_k3
2.074 INFO Using VIRTUAL_ENV: /var/lib/awx/venv/ansible
2.074 INFO Using PATH: /var/lib/awx/venv/ansible/bin:/var/lib/awx/venv/awx/bin:/opt/rh/rh-postgresql10/root/usr/bin:/var/lib/awx/venv/awx/bin:/var/lib/awx/venv/awx/bin:/opt/rh/rh-postgresql10/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
2.074 INFO Using PYTHONPATH: /var/lib/awx/venv/ansible/lib/python2.7/site-packages:
2.807 ERROR ansible-inventory 2.8.6
2.808 ERROR config file = /etc/ansible/ansible.cfg
2.808 ERROR configured module search path = [u'/var/lib/awx/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
2.808 ERROR ansible python module location = /usr/lib/python2.7/site-packages/ansible
2.808 ERROR executable location = /usr/bin/ansible-inventory
2.808 ERROR python version = 2.7.5 (default, Aug 7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
2.808 ERROR Using /etc/ansible/ansible.cfg as config file
2.808 ERROR host_list declined parsing /tmp/awx_1302_0cicirws/tmpsgddb_k3 as it did not pass it's verify_file() method
2.808 ERROR auto declined parsing /tmp/awx_1302_0cicirws/tmpsgddb_k3 as it did not pass it's verify_file() method
2.808 ERROR [WARNING]: Skipping 'curl -s GET "https://myserver/inventory" -H
2.808 ERROR "accept' as this is not a valid group definition
2.808 ERROR
2.808 ERROR Parsed /tmp/awx_1302_0cicirws/tmpsgddb_k3 inventory source with yaml plugin
2.808 INFO Processing JSON output...
2.809 INFO Loaded 0 groups, 0 hosts
2019-10-23 17:29:24,999 DEBUG awx.main.models.inventory Going to update inventory computed fields, pk=3
2019-10-23 17:29:25,038 DEBUG awx.main.models.inventory Finished updating inventory computed fields, pk=3, in 0.035 seconds
2.897 INFO Inventory import completed for test in 1.1s
我知道,AWX输出有点奇怪,因为它检测到卷曲行中的某些输出并将其标记为错误。它调用URL,结果大小相同,为200 OK。但是我不明白,错误在哪里。有没有其他方法可以解析JSON输出以从JSON响应中获取信息,但是我不知道另一种工具来验证清单文件(错误缝不是语法而是语义)。
也很有趣-当我从curl移除accept-header时,同步期间AWX失败。我尝试加载YAML。但是后端总是返回“ Content-type:application / json”。这对我来说很奇怪。
我不确定问题出在哪里-我仍然不确定这是JSON输出还是脚本本身。它在本地有效,例如ansible-inventory -i inventory.sh --graph
显示远程清单JSON中的所有内容。