Created
March 15, 2017 14:33
-
-
Save evrardjp/6612a4d3116ca1d13ba91497ae937f5d to your computer and use it in GitHub Desktop.
spot the difference
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
connection: local | |
tasks: | |
- name: simulate long running op (10 sec), wait for up to 30 sec, poll every 2 sec | |
command: /bin/sleep 10 | |
register: sleeptask | |
async: 30 | |
poll: 0 | |
- name: simulate an error on the command, and see if the task fails. | |
shell: "grep thispatterndoesntexist thisfiledoesntexist" | |
register: greptask | |
async: 30 | |
poll: 0 | |
- async_status: | |
jid: "{{ sleeptask.ansible_job_id }}" | |
failed_when: false | |
changed_when: false | |
register: sleeptaskstatus | |
until: sleeptaskstatus.finished | |
- async_status: | |
jid: "{{ greptask.ansible_job_id }}" | |
failed_when: greptaskstatus.stderr.find("No such file or directory") == -1 #If I don't find "no such file" then it's a failure. | |
changed_when: greptaskstatus.stderr.find("No such file or directory") != -1 #If I find it, changed! | |
register: greptaskstatus | |
until: greptaskstatus.finished | |
- debug: | |
var: item | |
with_items: | |
- "{{ greptask }}" | |
- "{{ sleeptask }}" | |
- "{{ greptaskstatus }}" | |
- "{{ sleeptaskstatus }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: Publish snapshot into public/integrated/ folder | |
shell: 'aptly publish snapshot -distribution="{{ artifacts_version }}-{{ distribution_release }}" miko-{{ artifacts_version }}-{{ distribution_release }} integrated' | |
register: aptly_snapshot_publish | |
#This can run for maximum 23h. | |
async: 82800 | |
poll: 0 | |
tags: | |
- aptly_publish | |
# To avoid CI build timeouts, we want to make sure ansible outputs to | |
# the console regularily. We do this using an async_status task. | |
- name: Poll async status | |
async_status: jid={{ aptly_snapshot_publish.ansible_job_id }} | |
register: job_merged_snapshot_publish_result | |
until: job_merged_snapshot_publish_result.finished | |
failed_when: job_merged_snapshot_publish_result.rc != 0 and job_merged_snapshot_publish_result.stderr.find('already used') == -1 | |
changed_when: job_merged_snapshot_publish_result.stderr.find('already used') == -1 | |
retries: 16560 | |
tags: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
`
TASK [async_status] ************************************************************
changed: [localhost]
TASK [debug] *******************************************************************
ok: [localhost] => (item={u'started': 1, u'finished': 0, u'results_file': u'/Users/jean0000/.ansible_async/350222488256.50223', u'ansible_job_id': u'350222488256.50223', 'changed': False}) => {
"item": {
"ansible_job_id": "350222488256.50223",
"changed": false,
"finished": 0,
"results_file": "/Users/jean0000/.ansible_async/350222488256.50223",
"started": 1
}
}
ok: [localhost] => (item={u'started': 1, u'finished': 0, u'results_file': u'/Users/jean0000/.ansible_async/133941466972.50200', u'ansible_job_id': u'133941466972.50200', 'changed': False}) => {
"item": {
"ansible_job_id": "133941466972.50200",
"changed": false,
"finished": 0,
"results_file": "/Users/jean0000/.ansible_async/133941466972.50200",
"started": 1
}
}
ok: [localhost] => (item={u'rc': 2, u'changed': True, u'stdout': u'', 'failed': False, u'ansible_job_id': u'350222488256.50223', u'warnings': [], u'cmd': u'grep thispatterndoesntexist thisfiledoesntexist', u'finished': 1, u'end': u'2017-03-15 14:29:54.101851', u'start': u'2017-03-15 14:29:53.916033', 'attempts': 1, u'stderr': u'grep: thisfiledoesntexist: No such file or directory', u'delta': u'0:00:00.185818', 'stdout_lines': [], 'failed_when_result': False}) => {
"item": {
"ansible_job_id": "350222488256.50223",
"attempts": 1,
"changed": true,
"cmd": "grep thispatterndoesntexist thisfiledoesntexist",
"delta": "0:00:00.185818",
"end": "2017-03-15 14:29:54.101851",
"failed": false,
"failed_when_result": false,
"finished": 1,
"rc": 2,
"start": "2017-03-15 14:29:53.916033",
"stderr": "grep: thisfiledoesntexist: No such file or directory",
"stdout": "",
"stdout_lines": [],
"warnings": []
}
}
ok: [localhost] => (item={u'cmd': [u'/bin/sleep', u'10'], u'stdout': u'', u'ansible_job_id': u'133941466972.50200', u'warnings': [], u'stdout_lines': [], u'changed': False, u'attempts': 3, u'failed': False, u'finished': 1, u'stderr': u'', u'rc': 0, u'delta': u'0:00:10.012003', u'end': u'2017-03-15 14:30:02.520023', u'failed_when_result': False, u'start': u'2017-03-15 14:29:52.508020'}) => {
"item": {
"ansible_job_id": "133941466972.50200",
"attempts": 3,
"changed": false,
"cmd": [
"/bin/sleep",
"10"
],
"delta": "0:00:10.012003",
"end": "2017-03-15 14:30:02.520023",
"failed": false,
"failed_when_result": false,
"finished": 1,
"rc": 0,
"start": "2017-03-15 14:29:52.508020",
"stderr": "",
"stdout": "",
"stdout_lines": [],
"warnings": []
}
}
PLAY RECAP *********************************************************************
localhost : ok=5 changed=1 unreachable=0 failed=0
`