1

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()).

William
  • 188
  • 1
  • 8
  • [The documentation dealing with variable precedence](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable) takes your exact var as an example to illustrate the overall subject. – Zeitounator Dec 22 '21 at 09:17
  • @Zeitounator, that's helpful, but I'm not sure how to use the precedence to solve this problem, which is overriding only sometimes. If I were running Ansible without AWX, precedence would easily solve the problem. – William Dec 22 '21 at 15:34
  • I don't get it. Why don't you change the user in your awx task in that case ? Same as changing it on the command line. Or put it in your inventory for the group/hosts.... precedence rules are the same in bare ansible and awx. Awx only launches playbooks using the ansible command line. – Zeitounator Dec 22 '21 at 16:12

1 Answers1

1

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.

William
  • 188
  • 1
  • 8