问题描述
下面是我的代码,总共需要大约 20 分钟。任务大约需要 1 分钟,循环运行 20 次,所以 20X1=20 分钟。如果 shell
模块中的任何任务失败,即 rc != 0
- name: Check DB connection with DBPING
shell: "java utils.dbping ORACLE_THIN {{ item | trim }}"
with_items: "{{ db_conn_dets }}"
delegate_to: localhost
为了加速任务,我决定并行运行它们,然后获取每个任务的成功或失败,如下所示。
- name: Check DB connection with DBPING
shell: "java utils.dbping ORACLE_THIN {{ item | trim }}"
with_items: "{{ db_conn_dets }}"
delegate_to: localhost
async: 600
poll: 0
register: dbcheck
- name: Result check
async_status:
jid: "{{ item.ansible_job_id }}"
register: _jobs
until: _jobs.finished
delay: 10
retries: 20
with_items: "{{ dbcheck.results }}"
现在!!在整个循环中,任务 Check DB connection with DBPING
在不到一分钟的时间内完成。但是,问题是所有任务 Result check
都会失败,即使任务 Check DB connection with DBPING
最终会成功,即 rc=0
以下是本应成功的示例失败任务 Result check
Failed: [remotehost] (item={'_ansible_parsed': True,'_ansible_item_result': True,'_ansible_no_log': False,u'ansible_job_id': u'234197058177.18294','_ansible_delegated_vars': {'ansible_delegated_host': u'localhost','ansible_host': u'localhost'},u'started': 1,'changed': True,'Failed': False,u'finished': 0,u'results_file': u'/home/ansbladm/.ansible_async/234197058177.18294','item': u'dbuser mypass dbhost:1521:mysid','_ansible_ignore_errors': None}) => {
"ansible_job_id": "234197058177.18294","attempts": 1,"changed": false,"finished": 1,"invocation": {
"module_args": {
"jid": "234197058177.18294","mode": "status"
}
},"item": {
"ansible_job_id": "234197058177.18294","changed": true,"Failed": false,"finished": 0,"item": "dbuser mypass dbhost:1521:mysid","results_file": "/home/ansbladm/.ansible_async/234197058177.18294","started": 1
},"msg": "Could not find job","started": 1
}
能否请您告诉我我的任务 Result check
的问题是什么,我如何确保它一直尝试直到任务 Check DB connection with DBPING
完成,从而在 .rc
完成时报告成功或失败}} shell
模块?
如果我能让 debug
模块打印 shell
的所有失败的 Check DB connection with DBPING
任务也很棒。
请提出建议。
解决方法
尽管这是对我的一组查询的部分答案。如果将来有完整的答案,我会接受。
将 delegate_to: localhost
添加到任务 Result check
inode 以解决该行为。
不过,我仍在等待代码在 debug
中显示所有失败的任务。