When Ansible has problems running plays against a host, it will output the name of the host into a file in the user's home directory ending in '.retry'. These are often not used and just cause clutter, is there a way to turn them off or put them in a different directory?
5 Answers
There are two options that you can add to the [defaults] section of the ansible.cfg file that will control whether or not .retry files are created and where they are created.
[defaults]
...
retry_files_enabled = True # Create them - the default
retry_files_enabled = False # Do not create them
retry_files_save_path = "~/" # The directory they will go into
# (home directory by default)
-
8Note that this only works for Ansible 1.9 and newer: github.com/ansible/ansible/commit/… Sep 21, 2015 at 7:25
-
5Note that retry files aren't created by default starting from Ansible 2.8: docs.ansible.com/ansible/latest/porting_guides/… Dec 14, 2019 at 18:57
You can disable creation of retry file in ansible by modifying ansible configuration file.
[defaults]
...
retry_files_enabled = False
Ansible looks for configuration file as follows
- ./ansible.cfg
- ~/.ansible.cfg
- /etc/ansible/ansible.cfg
Make sure to add your changes to the appropriate config file.
You can also turn the retry files off by setting an environment variable ANSIBLE_RETRY_FILES_ENABLED
to 0
:
$ ANSIBLE_RETRY_FILES_ENABLED=0 ansible-playbook ...
Funny enough, I had a similar issue with the retry file, but as I am working with a whole team, I'd rather not touch the config.
What I decided to do instead was to remove the retry file(s) as part of the run from within the playbook:
#Clean up the admin node - basic housekeeping
- hosts:
- admin
gather_facts: no
tasks:
- name: remove retry file
file:
path: "{{ item }}"
state: absent
with_fileglob:
- "{{playbook_dir}}/*.retry"
-
I think especially in a team, using a common and sane config is much better than working around it this way, which is also kinda config, but less obvious. Jul 21, 2020 at 14:53
-
1You are right. This is definitely not for times when you can do it properly. It grew out of desperation when you have 27 other people on the team in 7 different teams under 10 different managers... Jul 23, 2020 at 6:49
Uncomment the lines in the default ansible.cfg
file
to
retry_files_enabled = True
retry_files_save_path = ~/.ansible-retry