简体   繁体   中英

Optional Variable Override in Ansible Playbook

I'm using AWX as a task runner to run a variety of Ansible modules. Some of the Ansible modules are third-party modules whose parameters I can't control without forking the module, which is undesirable for a variety of reasons.

AWX supplies ansible_user as one variable that is used by some of the modules I'm using, and I'm trying to allow a user to some hosts by setting another variable, user_override .

I first thought to simply add the line ansible_user: "{{ user_override | default(ansible_user) }}" to the task's parameters, which would work... but the modules in question don't accept credentials via parameters. My next thought was to add a vars: entry to the playbook and supply the override there via the same markup as above. This unfortunately results in the error recursive loop detected in template string , which has been the bane of my existence while working through this problem.

I've also tried using the if/else syntax and intermediate variables, but neither appear to solve this problem.

How can I achieve this override functionality without forking AWX or the module in question?

Mods: This is distinct from the pile of questions asking about simple variable defaulting because the existing questions aren't in the context of AWX or can be solved by simply using default() or default(lookup()) .

At this point, I'm pretty sure that the thing I (the asker) was trying to do is intended to be done by just sometimes setting a value, but some challenging-to-anonymize constraints in our software make that somewhere between challenging and not an option.

A sideways solution to the particular problem of overriding the user is that AWX sets the username in remote_user as well as ansible_user , which is then used by networkcli . So you can use the line `remote_user: "{{ override_user | default(ansible_user) }}". This doesn't help generally , but does answer the question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM