-
- You can merge
local tmpcfgline with the next one - I ended up using
-p "$PWD"so that behaviour wrt relative paths in ansible.cfg is same as if you would execute ansible normally. Technically, it should be doing it reversibly (reverse loop and save into same location), but that is much more complicated.
- You can merge
-
- The exit code of
localwill overwrite the exit code ofmktempif you merge both lines
f() { local foo=$(mktemp -p /bar/ ansible-XXXXXXXXXX.cfg) ; echo $? ; }; f mktemp: failed to create file via template ‘/bar/ansible-XXXXXXXXXX.cfg’: No such file or directory 0 f() { local foo; foo=$(mktemp -p /bar/ ansible-XXXXXXXXXX.cfg) ; echo $? ; }; f mktemp: failed to create file via template ‘/bar/ansible-XXXXXXXXXX.cfg’: No such file or directory 1In this simple script it doesn't really care but generally I would recommend to declare and assign variables separately.
- Well.. yes, relative paths are a problem with this version.
-p $PWDwill only solve this for ./ansible.cfg (in current directory). If you defined relative paths in ~/.ansible.cfg then you would need an alternative solution. I came up with this IF condition:
if [ -f "${ANSIBLE_CONFIG}" ] && [ -w "${ANSIBLE_CONFIG%/*}" ]; then tmpcfg=$(mktemp -p "${ANSIBLE_CONFIG%/*}" ansible-XXXXXXXXXX.cfg) elif [ -f ./ansible.cfg ]; then tmpcfg=$(mktemp -p "${PWD}" ansible-XXXXXXXXXX.cfg) elif [ -f ~/.ansible.cfg ]; then tmpcfg=$(mktemp -p "${HOME}" ansible-XXXXXXXXXX.cfg) elif [ -f /etc/ansible/ansible.cfg ] && [ -w /etc/ansible/ ]; then tmpcfg=$(mktemp -p /etc/ansible ansible-XXXXXXXXXX.cfg) else tmpcfg=$(mktemp -p /tmp/ ansible-XXXXXXXXXX.cfg) fiBut this will also not solve the problem if you use relative paths in multiple files and is too much for this simple workaround.
I think-p PWDwill be the most use case, so I will adjust the script above. Thanks @ignatenkobrain :)Edited by Robért - The exit code of
-
It merges all possible files and overwrites options if they already exist, yes. There're certainly some usecases where real merging of some options is more desired. But this can get tricky in a hurry, so it goes beyond this simple workaround.
But you could try developing your own solution to work around your problem.
With
crudini --get /etc/ansible/ansible.cfg defaults strategy_pluginsyou get the current value of the strategy_plugins option. Save the output to an variable and put a loop around it. At the end set your merged value with the --set ofcrudinioption.
Please register or sign in to comment