3

In one of my playbooks I start a service and poll for its status before moving onto the next task like the following:

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

This logs a message each time it queries the URL which looks like

FAILED - RETRYING: TASK: Poll for service status

Is there a way to customise this message? Specifically remove the word FAILED.

U880D
  • 8,601
  • 6
  • 24
  • 40
N.L
  • 33
  • 4
  • 1
    Yes. Ansible code is [available on GitHub](https://github.com/ansible/ansible). Fork and customise. Or create a callback plugin to suit your needs. – techraf Feb 10 '18 at 22:29

1 Answers1

1

After grepping around, I found the "FAILED - RETRYING" message in the default output callback (read about callbacks here). That means you can change the callback in ansible.cfg to something that suits your needs- or make your own. You can even search the code for v2_runner_retry to see the various outputs.

For instance, here's what stdout_callback=oneline returns. There are no "retrying" messages even at -vv. It still says "FAILED" but that's because it actually 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"}

Aside from setting it in ansible.cfg the documentation implies it can be done in a role. I have no idea how.

As @techraf said, the Ansible folks are pretty good at reviewing pull requests.

tedder42
  • 23,519
  • 13
  • 86
  • 102