您可以通过Ansible重试/直到模块更改临时消息吗?

时间:2018-02-10 22:23:56

标签: ansible

在我的一个剧本中,我开始提供服务并对其状态进行轮询,然后再进行下一个任务,如下所示:

- name: Poll for service status
  uri:
    url: http://some-service/status
  register: response
  until: response.status == 200
  retries: 12
  delay: 10

每次查询看似

的网址时都会记录一条消息
FAILED - RETRYING: TASK: Poll for service status

有没有办法自定义此消息?明确删除单词FAILED

1 个答案:

答案 0 :(得分:0)

在逛了一圈后,我找到了" FAILED - RETRYING"消息in the default output callbackread about callbacks here)。这意味着您可以将ansible.cfg中的回调更改为适合您需求的回调 - 或者创建自己的回调。您甚至可以search the code for v2_runner_retry查看各种输出。

例如,stdout_callback=oneline返回的是什么。没有"重试"即使在-vv也是如此。它仍然说" FAILED"但那是因为它确实失败了。

ansible-playbook -vvi localhost, p.yml
ansible-playbook 2.4.1.0
  config file = /opt/app/ansible.cfg
  configured module search path = ['/opt/app/library']
  ansible python module location = /usr/local/lib/python3.5/dist-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.5.2 (default, Sep 14 2017, 22:51:06) [GCC 5.4.0 20160609]
Using /opt/app/ansible.cfg as config file
1 plays in p.yml
META: ran handlers
localhost | FAILED! => {"attempts": 3,"changed": false,"content": "","failed": true,"msg": "Status code was not [200]: Request failed: <urlopen error [Errno -2] Name or service not known>","redirected": false,"status": -1,"url": "http://some-service/status"}

除了在ansible.cfg中设置它之外,文档暗示它可以在角色中完成。我不知道怎么做。

正如@techraf所说,Ansible人员非常擅长审查拉取请求。