【问题标题】:How to get the Ansible playbook run failure information如何获取 Ansible playbook 运行失败信息
【发布时间】:2020-06-24 04:36:17
【问题描述】:

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

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

为了进一步调试问题,我重新运行了剧本,将详细级别设置为 3。在详细级别 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

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

【问题讨论】:

  • 如果您运行直接打印到日志的ssh 命令会发生什么?

标签: shell ansible


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2022-01-12
    • 2020-10-11
    • 2021-01-17
    • 2017-09-29
    • 1970-01-01
    • 2020-03-28
    • 2017-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多