I'd like to make Ansible run a task per some object found at runtime. For example one per file in a specified directory or one per running process. Is there a way to implement this inside of task/playbook? I'd like the result to be integrated into the normal output as a task in its own rights, ideally with adjusted task and "register" variable name.

Unfortunately all the examples I can find are static definitions.


You can use a include for this. Here is an example where i read all databases in a mysql host and then include some tasks. You can also give some variables to this include.

- command: mysql -u root -e 'show databases;'
  register: databases

- include: soma_tasks.yml db={{item}}
  with_items: databases.stdout_lines
  when: item not "Database"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.