160

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?

Jonas
  • 121,568
  • 97
  • 310
  • 388
Asfand Qazi
  • 6,586
  • 4
  • 32
  • 34

5 Answers5

202

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)
Asfand Qazi
  • 6,586
  • 4
  • 32
  • 34
  • 8
    Note that this only works for Ansible 1.9 and newer: https://github.com/ansible/ansible/commit/c15b47fb7bbcca965089afc15c2dacf2f8120758 – hudolejev Sep 21 '15 at 07:25
  • 5
    Note that retry files aren't created by default starting from Ansible 2.8: https://docs.ansible.com/ansible/latest/porting_guides/porting_guide_2.8.html#retry-file-creation-default – Slava Semushin Dec 14 '19 at 18:57
65

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

  1. ./ansible.cfg
  2. ~/.ansible.cfg
  3. /etc/ansible/ansible.cfg

Make sure to add your changes to the appropriate config file.

Per Lundberg
  • 3,837
  • 1
  • 36
  • 46
AnshBikram
  • 2,028
  • 13
  • 8
12

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 ...
Tomas Tomecek
  • 6,226
  • 3
  • 30
  • 26
0

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"
Lefty G Balogh
  • 1,771
  • 3
  • 26
  • 40
  • 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. – Axel Beckert Jul 21 '20 at 14:53
  • 1
    You 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... – Lefty G Balogh Jul 23 '20 at 06:49
-1

Uncomment the lines in the default ansible.cfg file to

retry_files_enabled = True
retry_files_save_path = ~/.ansible-retry
DanielM
  • 3,598
  • 5
  • 37
  • 53
Sarangz
  • 57
  • 2