如何获取 Ansible 剧本运行失败信息



我一直在执行 Ansible 剧本。通常,如果剧本成功运行,它将返回"0"。但目前在我的环境中,即使剧本执行失败,Ansible 控制台上也没有返回代码或任何错误消息。此剧本应在 2-3 分钟内执行,并在测试环境中观察到相同的内容。

问题:在我们当前的生产环境中,它需要超过2-4天的时间,然后在没有任何错误消息或失败原因的情况下失败。

为了进一步调试问题,我重新运行了剧本,将详细级别设置为 3。在详细级别三中,我只能看到记录以下信息,但没有有关失败的信息。

ansible-playbook 2.7.0
config file = /home/dbrun/.ansible.cfg 
configured module search path = ['/home/dbrun/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] 
ansible python module location = /home/dbrun/miniconda3/envs/dbrun/lib/python3.6/site-packages/ansible 
executable location = /home/dbrun/miniconda3/envs/dbrun/bin/ansible-playbook 
python version = 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 19:07:31) [GCC 7.3.0] 
Using /home/dbrun/.ansible.cfg as config file 
Parsed /home/dbrun/dbRunPlaybooks/4875-25/hosts/PROD/hosts inventory source with ini plugin 
**PLAYBOOK: RPCStart.yml ********************************************************* **
1 plays in /home/dbrun/dbRunPlaybooks/4875-25/Cognos/RPCStart.yml 
**PLAY [primary_host] ************************************************************** 
META: ran handlers 
**TASK [Start RPC process] ******************************************************* 
task path: /home/dbrun/dbRunPlaybooks/4875-25/Cognos/RPCStart.yml:13 
ESTABLISH SSH CONNECTION FOR USER: cog84 
SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'IdentityFile="/home/dbrun/dbRunPlaybooks/4875-25/hosts/PROD/ssh_keys/dbrun_4875_25_prd"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=cog84 -o ConnectTimeout=100 -o ControlPath=/home/dbrun/.ansible/cp/ea2d6bf111 frasmhvpp11.de.db.com '/bin/ksh -c ". $HOME/.profile;cd /export/cognos/cognos/cognos_rpc;/usr/bin/nohup /export/cognos/cognos/cognos_rpc/run.sh > /dev/null 2 >&1 &"'

以下是我的剧本中的内容:

- hosts: primary_host
gather_facts: no
remote_user: cog84
tasks:

- name: Start RPC process
raw: /bin/ksh -c  ". $HOME/.profile;cd /export/cognos/cognos/cognos_rpc;/usr/bin/nohup /export/cognos/cognos/cognos_rpc/run.sh > /dev/null 2 >&1 &"
register: output_result
- debug: var=output_result.stdout_lines

- name: Date
raw: date
register: result

任何调试指针都会有所帮助。

我发现了这个问题。问题不在于 ansible。问题在于我尝试使用 ansible 剧本运行的 shell 脚本。

最新更新