DEFAULT_GATHER_TIMEOUT deprecated - alternatives?

I’m seeing this message on running my playbooks:


[DEPRECATION WARNING]: DEFAULT_GATHER_TIMEOUT option, the module_defaults keyword is a more generic version and can apply to all calls to the M(ansible.builtin.gather_facts) or M(ansible.builtin.setup) actions, use module_defaults instead. This feature will be removed from ansible-core in version 2.18. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.


I’d like to “do things the right way” and prepare for new Ansible versions, but I’m struggling to decide how to update my config/playbooks. It seems like using module_defaults requires updating all of my playbooks, whereas I can set gather_timeout in [defaults] on my ansible.cfg. We use this, for example, to swap in a “slow config” when deploying to systems with slow network connections. I don’t want to have to build a “slow config” version of each of my dozens of playbooks.

I see there was some discussion in the Google Group at https://groups.google.com/g/ansible-project/c/ZgVmYkuHj5M?pli=1 but it didn’t really go anywhere.

You do have to update all your playbooks, but if you plan ahead, you won’t have to make a “slow config” version of each of your playbooks. The following scheme seems to work, although I have done extremely limited testing:

---
# gather-test.yml
- name: Experiment with gather_timeout
  hosts: all
  module_defaults:
    ansible.builtin.setup:
      gather_timeout: '{{ gather_timeout | default(10) }}'
  tasks:
    - name: Show each host's gather_timeout
      ansible.builtin.debug:
        msg: '{{ gather_timeout | default("(defaulted to 10)") }}'

Now you can set a “gather_timeout” variable in your group_vars, host_vars, or your inventory for hosts or groups that need a value other than the default.

Doing that removes your need to “swap in a ‘slow config’” ansible.cfg for those hosts. They should just do the Right Thing from then on.

If you really plan ahead — and I’m kicking myself for not thinking of this before I modified all of our playbooks — you can create another playbook that uses ansible.builtin.blockinfile to maintain your “global” module_defaults (not necessarily limited to ansible.builtin.setup either) across all your playbooks. That way you’re prepared the next time a change in Ansible or your own policies or whatever necessitates such sweeping changes.

Thanks! Still a shame to need to update playbooks, but it’s good to at least have a somewhat clean way to do it, and not need to create duplicate copies of all the playbooks.

1 Like

Kind of a meta-comment: What I’m really curious about is why your post from February 23 would be popping up in my feed in mid-July. I’m glad it did, because it gave me the incentive to do the experiment I’m been putting of for a long time now, so I have a way forward I’m more comfortable with. Still, why now?