Ansible 异步任务收集结果:找不到工作
Ansible async task collecting results: could not find job
我正在尝试触发并忘记一些任务,然后收集结果。这是我的剧本:
---
- hosts: node2
gather_facts: yes
tasks:
- name: 'Some long script no 1 on node2'
shell: "time sleep $[ ( $RANDOM % 20 ) + 20 ]s"
async: 40
poll: 0
register: script1
- name: 'Another long script no 2 on node2'
shell: "time sleep $[ ( $RANDOM % 20 ) + 20 ]s"
async: 40
poll: 0
register: script2
- hosts: node2
tasks:
- name: "Collect results"
async_status:
jid: loop_item.ansible_job_id
loop:
- script1
- script2
loop_control:
loop_var: loop_item
register: async_poll_results
until: async_poll_results.finished
retries: 30
当我 运行 它时,我收到以下错误:
PLAY [node2] ****************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************
ok: [hostname]
TASK [Some long script no 1 on node2] ***************************************************************************************************
changed: [hostname] => {"ansible_job_id": "814448842231.125544", "changed": true, "finished": 0, "results_file": "/home/external.kamil.sacharczuk/.ansible_async/814448842231.125544", "started": 1}
TASK [Another long script no 2 on node2] ************************************************************************************************
changed: [hostname] => {"ansible_job_id": "586999441005.125616", "changed": true, "finished": 0, "results_file": "/home/external.kamil.sacharczuk/.ansible_async/586999441005.125616", "started": 1}
PLAY [node2] ****************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************
ok: [hostname]
TASK [Collect results] ******************************************************************************************************************
failed: [hostname] (item=script1) => {"ansible_job_id": "loop_item.ansible_job_id", "attempts": 1, "changed": false, "finished": 1, "loop_item": "script1", "msg": "could not find job", "started": 1}
failed: [hostname] (item=script2) => {"ansible_job_id": "loop_item.ansible_job_id", "attempts": 1, "changed": false, "finished": 1, "loop_item": "script2", "msg": "could not find job", "started": 1}
to retry, use: --limit @xxxxxxxxx
PLAY RECAP ******************************************************************************************************************************
hostname : ok=4 changed=2 unreachable=0 failed=1
真的不知道为什么我会收到这个 "could not find job"。我首先尝试 运行 这个 "collect" 本地任务,然后我发现这个工作结果存储在 node2 上,所以我 运行 它在那里。尝试收集或不收集事实。也试过使用
hostvars['hostname'][loop_item][ansible_job_id]
但这给了我和这里一样的错误。
如有任何帮助,我们将不胜感激!
PS。我是 运行ning ansible 2.6.1
请尝试以下正确引用::
- hosts: localhost
gather_facts: false
tasks:
- name: 'Some long script no 1 on node2'
shell: "time sleep $[ ( $RANDOM % 20 ) + 20 ]s"
async: 40
poll: 0
register: script1
- name: 'Another long script no 2 on node2'
shell: "time sleep $[ ( $RANDOM % 20 ) + 20 ]s"
async: 40
poll: 0
register: script2
- hosts: localhost
tasks:
- name: "Collect results"
async_status:
jid: "{{ loop_item.ansible_job_id }}"
loop:
- "{{ script1 }}"
- "{{ script2 }}"
loop_control:
loop_var: loop_item
register: async_poll_results
until: async_poll_results.finished
retries: 30
如果有人到这里来搜索此错误消息,'could not find job' 还有另一个原因。如果工作 运行 为 become
,那么应该是 async_status
。如果您尝试 async_status for become
-job 而没有将 become
添加到 async_status
模块,它将失败并显示此消息。
我正在尝试触发并忘记一些任务,然后收集结果。这是我的剧本:
---
- hosts: node2
gather_facts: yes
tasks:
- name: 'Some long script no 1 on node2'
shell: "time sleep $[ ( $RANDOM % 20 ) + 20 ]s"
async: 40
poll: 0
register: script1
- name: 'Another long script no 2 on node2'
shell: "time sleep $[ ( $RANDOM % 20 ) + 20 ]s"
async: 40
poll: 0
register: script2
- hosts: node2
tasks:
- name: "Collect results"
async_status:
jid: loop_item.ansible_job_id
loop:
- script1
- script2
loop_control:
loop_var: loop_item
register: async_poll_results
until: async_poll_results.finished
retries: 30
当我 运行 它时,我收到以下错误:
PLAY [node2] ****************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************
ok: [hostname]
TASK [Some long script no 1 on node2] ***************************************************************************************************
changed: [hostname] => {"ansible_job_id": "814448842231.125544", "changed": true, "finished": 0, "results_file": "/home/external.kamil.sacharczuk/.ansible_async/814448842231.125544", "started": 1}
TASK [Another long script no 2 on node2] ************************************************************************************************
changed: [hostname] => {"ansible_job_id": "586999441005.125616", "changed": true, "finished": 0, "results_file": "/home/external.kamil.sacharczuk/.ansible_async/586999441005.125616", "started": 1}
PLAY [node2] ****************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************
ok: [hostname]
TASK [Collect results] ******************************************************************************************************************
failed: [hostname] (item=script1) => {"ansible_job_id": "loop_item.ansible_job_id", "attempts": 1, "changed": false, "finished": 1, "loop_item": "script1", "msg": "could not find job", "started": 1}
failed: [hostname] (item=script2) => {"ansible_job_id": "loop_item.ansible_job_id", "attempts": 1, "changed": false, "finished": 1, "loop_item": "script2", "msg": "could not find job", "started": 1}
to retry, use: --limit @xxxxxxxxx
PLAY RECAP ******************************************************************************************************************************
hostname : ok=4 changed=2 unreachable=0 failed=1
真的不知道为什么我会收到这个 "could not find job"。我首先尝试 运行 这个 "collect" 本地任务,然后我发现这个工作结果存储在 node2 上,所以我 运行 它在那里。尝试收集或不收集事实。也试过使用
hostvars['hostname'][loop_item][ansible_job_id]
但这给了我和这里一样的错误。
如有任何帮助,我们将不胜感激!
PS。我是 运行ning ansible 2.6.1
请尝试以下正确引用::
- hosts: localhost
gather_facts: false
tasks:
- name: 'Some long script no 1 on node2'
shell: "time sleep $[ ( $RANDOM % 20 ) + 20 ]s"
async: 40
poll: 0
register: script1
- name: 'Another long script no 2 on node2'
shell: "time sleep $[ ( $RANDOM % 20 ) + 20 ]s"
async: 40
poll: 0
register: script2
- hosts: localhost
tasks:
- name: "Collect results"
async_status:
jid: "{{ loop_item.ansible_job_id }}"
loop:
- "{{ script1 }}"
- "{{ script2 }}"
loop_control:
loop_var: loop_item
register: async_poll_results
until: async_poll_results.finished
retries: 30
如果有人到这里来搜索此错误消息,'could not find job' 还有另一个原因。如果工作 运行 为 become
,那么应该是 async_status
。如果您尝试 async_status for become
-job 而没有将 become
添加到 async_status
模块,它将失败并显示此消息。