-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
backup files in host_vars override vars.yml #17382
Comments
I've been able to replicate this. I think it's due to the behaviour of the You can avoid those files being loaded with an extra condition on the for loop that follows, but I don't know if that's desirable behaviour.
|
Same bug here with group_vars. |
Thanks @george-buckerfield, that's exactly the behaviour I'd be wanting. I've looked at that part of the code and agree with your take on it. My take on desirable behaviour: saving with a "~" extension for backup files is the default behaviour for both vim & emacs, so makes sense to exclude these when parsing hostvars and groupvars. Alternatively might be to reverse the sort order, so that backup files were parsed first and over-written by variables in the actual file. (Personally think that's less transparent than just not parsing it at all though.) Does anyone want a pull request for this, or is more discussion needed about whether or not this is desireable behaviour? |
@rodmanning I had a PR ready to go a while back, so I've submitted it. Happy to modify it based on any feedback though. |
fixes ansible#17382 alternate to ansible#22979 deal with cases in which group/host have . in name updated as per feedbck only be strict about extension when doing dirs also avoid ~ endings
ISSUE TYPE
COMPONENT NAME
host_vars configuration
ANSIBLE VERSION
CONFIGURATION
Added vault password file path to ansible.cfg, nothing else.
OS / ENVIRONMENT
Arch linux (x86_64)
SUMMARY
When reading host_vars, ansible reads vars from a file name "vars.yml~" with priority over a file name "vars.yml". The "vars.yml~" file was created by editing the original file with emacs, which saves the backup by appending a "~" to the filename.
STEPS TO REPRODUCE
Create host_vars in a folder as follows:
When connecting to a host (e.g. ansible -i hosts all -m ping), ansible will use the vars saved in vars.yml~.
EXPECTED RESULTS
Expected to connect with 'root' on port 22, etc.
ACTUAL RESULTS
Ansible generated an ssh command for the incorrect user/port.
The text was updated successfully, but these errors were encountered: