0
votes

I am new to ansible and trying to figure out how can I call one playbook from another playbook in loop. I also want to consume the output back in master playbook. Not sure if it could be possible in Ansible.

Below is a stub from other programming languages -

masterplaybook.yml - from where I want to invoke auditplaybook

   for devicePair in devicePairList
        output = auditdevice.yml -e "d1=devicePair.A d2=devicePair.B"
    save/process output

auditdevice.yml playbook is using d1 and d2 as hosts on which it is performing auditing, running commands etc. It is performing audit on dynamic inventory passed as part of argument.

Is it possible to achieve above using Ansible? If yes, can someone point to any example?

1
As pointed out by Vladimir, this is not possible with include_playbook. But include_tasks can be used in a task with a loop. See the doc about including and importingZeitounator
Is it possible to include play's into a loop? As I need to run play on dynamic inventory.sunder
No. You can specify the play hosts as a variable though.Zeitounator

1 Answers

1
votes

Q: "How can I call one playbook from another playbook in the loop?"

A: It is not possible. Quoting from import_playbook

"You cannot use this action inside a play."

See the example.


ansible-runnerexample