I am writing a role to export configurations from Ansible AWX deployment. I want to loop over the items to export as follows. How is something like this possible?
- name: Export Config
awx.awx.export:
"{{ item }}": []
controller_host: ...
controller_username: ...
controller_password: ...
loop:
- projects
- inventory
- applications
- credentials
Whereby it is possible to have dynamic or variable values, it is not possible to have tasks with dynamic parameter keys.
Even using Templating (Jinja2) with
import_tasks
module – Import a task list, please take note about What's the difference betweeninclude_tasks
andimport_tasks
?, such approach will run into errors.A minimal example
dyn_task.yml
main.yml
will result into an error and output of
as the parameter became not resolved.
It might be possible via
resulting into an correct and expected output of
but I would consider this as very bad practice here in this case and recommend to use such not at all. See What are the uses of Self Modifying Code (SMC)?
Summary
To summarize the above description, either you can't or it is recommended not to do such.
And for completeness
whereby the
dest
path needs to be the path under in example/var/lib/awx/projects/
.