我已经开发了一个Extremeley简单自定义ansible
模块,其大致过程如下:
(只需在此处发布main
)
try:
resp = requests.post(_update_endpoint, data=json.dumps(PAYLOAD), headers=HEADERS, verify=False)
result = resp.json()
except Exception as ansibleException:
module.fail_json(msg=ansibleException)
module.log(str(result))
if result['status'] != 'succeeded':
module.fail_json(msg=result) else:
module.exit_json(changed=True, msg=result)
当我尝试在没有async
的情况下进行入侵时,一切正常。
但是,以下调用失败,并显示一条不太有用的消息:
- name: update.yml --> Perform custom updates
pack_update:
pack: "{{ item.key }}"
revision: "{{ item.value.revision }}"
st2_api_key: "{{ vault_st2_keys[inventory_hostname.split('.')[0]][inventory_hostname.split('.')[2]] if 'cpe' in group_names else vault_st2_keys[inventory_hostname.split('.')[0]]['central'] }}"
update_endpoint: https://{{ inventory_hostname }}:8080/api/v2/sync_execution
ca_cert_path: "/etc/ssl/certs/ca-certificates.crt"
async: 10000
poll: 0
with_dict: "{{ packs_custom_revisions }}"
register: async_results
- name: update_custom_packs.yml -> Await packs update completion
async_status:
jid: "{{ async_result_item.ansible_job_id }}"
loop: "{{ async_results.results }}"
loop_control:
loop_var: "async_result_item"
register: async_poll_results
until: async_poll_results.finished
retries: 300
{
"_ansible_parsed": true,
"stderr_lines": [
"Traceback (most recent call last):",
" File \"/home/ansible/.ansible/tmp/ansible-tmp-1553074056.44-249913915769205/AnsiballZ_pack_update.py\", line 113, in <module>",
" _ansiballz_main()",
" File \"/home/ansible/.ansible/tmp/ansible-tmp-1553074056.44-249913915769205/AnsiballZ_pack_update.py\", line 105, in _ansiballz_main",
" invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)",
" File \"/home/ansible/.ansible/tmp/ansible-tmp-1553074056.44-249913915769205/AnsiballZ_pack_update.py\", line 48, in invoke_module",
" imp.load_module('__main__', mod, module, MOD_DESC)",
" File \"/tmp/ansible_pack_update_payload_4Jy12u/__main__.py\", line 115, in <module>",
" File \"/tmp/ansible_pack_update_payload_4Jy12u/__main__.py\", line 104, in main",
" File \"/usr/local/lib/python2.7/dist-packages/requests/models.py\", line 897, in json",
" return complexjson.loads(self.text, **kwargs)",
" File \"/usr/lib/python2.7/json/__init__.py\", line 339, in loads",
" return _default_decoder.decode(s)",
" File \"/usr/lib/python2.7/json/decoder.py\", line 364, in decode",
" obj, end = self.raw_decode(s, idx=_w(s, 0).end())",
" File \"/usr/lib/python2.7/json/decoder.py\", line 382, in raw_decode",
" raise ValueError(\"No JSON object could be decoded\")",
"ValueError: No JSON object could be decoded"
],
"changed": false,
"ansible_job_id": "572687228702.10660",
"_ansible_item_result": true,
"msg": "Traceback (most recent call last):\n File \"/home/ansible/.ansible/tmp/ansible-tmp-1553074056.44-249913915769205/async_wrapper.py\", line 147, in _run_module\n (filtered_outdata, json_warnings) = _filter_non_json_lines(outdata)\n File \"/home/ansible/.ansible/tmp/ansible-tmp-1553074056.44-249913915769205/async_wrapper.py\", line 88, in _filter_non_json_lines\n raise ValueError('No start of json char found')\nValueError: No start of json char found\n",
"finished": 1,
"data": "",
"_ansible_no_log": false,
"_ansible_item_label": {
"_ansible_parsed": true,
"_ansible_item_result": true,
"_ansible_item_label": {
"key": "email_connector",
"value": {
"revision": "develop"
}
},
"ansible_job_id": "572687228702.10660",
"failed": false,
"started": 1,
"changed": true,
"item": {
"key": "email_connector",
"value": {
"revision": "develop"
}
},
"finished": 0,
"results_file": "/home/ansible/.ansible_async/572687228702.10660",
"_ansible_ignore_errors": null,
"_ansible_no_log": false
},
"cmd": "/home/ansible/.ansible/tmp/ansible-tmp-1553074056.44-249913915769205/AnsiballZ_pack_update.py",
"attempts": 1,
"stderr": "Traceback (most recent call last):\n File \"/home/ansible/.ansible/tmp/ansible-tmp-1553074056.44-249913915769205/AnsiballZ_pack_update.py\", line 113, in <module>\n _ansiballz_main()\n File \"/home/ansible/.ansible/tmp/ansible-tmp-1553074056.44-249913915769205/AnsiballZ_pack_update.py\", line 105, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/home/ansible/.ansible/tmp/ansible-tmp-1553074056.44-249913915769205/AnsiballZ_pack_update.py\", line 48, in invoke_module\n imp.load_module('__main__', mod, module, MOD_DESC)\n File \"/tmp/ansible_pack_update_payload_4Jy12u/__main__.py\", line 115, in <module>\n File \"/tmp/ansible_pack_update_payload_4Jy12u/__main__.py\", line 104, in main\n File \"/usr/local/lib/python2.7/dist-packages/requests/models.py\", line 897, in json\n return complexjson.loads(self.text, **kwargs)\n File \"/usr/lib/python2.7/json/__init__.py\", line 339, in loads\n return _default_decoder.decode(s)\n File \"/usr/lib/python2.7/json/decoder.py\", line 364, in decode\n obj, end = self.raw_decode(s, idx=_w(s, 0).end())\n File \"/usr/lib/python2.7/json/decoder.py\", line 382, in raw_decode\n raise ValueError(\"No JSON object could be decoded\")\nValueError: No JSON object could be decoded\n",
"invocation": {
"module_args": {
"jid": "572687228702.10660",
"mode": "status"
}
},
"async_result_item": {
"_ansible_parsed": true,
"_ansible_item_result": true,
"_ansible_no_log": false,
"ansible_job_id": "572687228702.10660",
"failed": false,
"started": 1,
"changed": true,
"item": {
"key": "email_connector",
"value": {
"revision": "develop"
}
},
"finished": 0,
"results_file": "/home/ansible/.ansible_async/572687228702.10660",
"_ansible_ignore_errors": null,
"_ansible_item_label": {
"key": "email_connector",
"value": {
"revision": "develop"
}
}
},
"_ansible_ignore_errors": null
}
有什么建议吗?
编辑__1:__ request(s)
发送是同步的,
edit__2:我注意到的是,当我运行模块__without 时,每次调用都会出现以下错误,但是该模块实际上在运行
{
"_ansible_parsed": false,
"changed": false,
"_ansible_item_label": {
"value": {
"revision": "develop"
},
"key": "email_connector"
},
"module_stderr": "Shared connection to my.corporate.env.domain closed.\r\n",
"_ansible_item_result": true,
"module_stdout": "Traceback (most recent call last):\r\n File \"/home/ansible/.ansible/tmp/ansible-tmp-1553075446.57-73318930950997/AnsiballZ_pack_update.py\", line 113, in <module>\r\n _ansiballz_main()\r\n File \"/home/ansible/.ansible/tmp/ansible-tmp-1553075446.57-73318930950997/AnsiballZ_pack_update.py\", line 105, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File \"/home/ansible/.ansible/tmp/ansible-tmp-1553075446.57-73318930950997/AnsiballZ_pack_update.py\", line 48, in invoke_module\r\n imp.load_module('__main__', mod, module, MOD_DESC)\r\n File \"/tmp/ansible_pack_update_payload_qgGmmz/__main__.py\", line 120, in <module>\r\n File \"/tmp/ansible_pack_update_payload_qgGmmz/__main__.py\", line 108, in main\r\n File \"/tmp/ansible_pack_update_payload_qgGmmz/ansible_pack_update_payload.zip/ansible/module_utils/basic.py\", line 2369, in fail_json\r\n File \"/tmp/ansible_pack_update_payload_qgGmmz/ansible_pack_update_payload.zip/ansible/module_utils/basic.py\", line 2341, in _return_formatted\r\n File \"/tmp/ansible_pack_update_payload_qgGmmz/ansible_pack_update_payload.zip/ansible/module_utils/basic.py\", line 522, in remove_values\r\n File \"/tmp/ansible_pack_update_payload_qgGmmz/ansible_pack_update_payload.zip/ansible/module_utils/basic.py\", line 505, in _remove_values_conditions\r\nTypeError: Value of unknown type: <type 'exceptions.ValueError'>, No JSON object could be decoded\r\n",
"item": {
"value": {
"revision": "develop"
},
"key": "email_connector"
},
"rc": 1,
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"_ansible_ignore_errors": null,
"_ansible_no_log": false
}