I am trying to “include” a lot of other playbooks in a “playbook of playbooks” (I am aware, and have tried to use, the import_playbook and include modules to no avail), and am trying to apply the ignore_errors: yes to the imported/included playbook; since I am testing, and not all hosts are available, I would like to ignore the connection errors.
How can I write my main playbook (all-programs.yml) such that I can run through playbooks/program[A-Z].yml while ignoring errors should they occur?
Scenario:
I am running Ansible v. 2.7.10, with the following layout
. ├── group_vars │ └── superGroup │ ├── vars.yml │ └── vault.yml ├── hosts ├── playbooks │ ├── **all****-programs.****yml** # This is the playbook that I am struggling to write │ ├── programA.yml │ ├── programB.yml │ ├── programC.yml│ …` │
├── roles
│ ├── programA
│ │ └── tasks
│ │ └── main.yml
│ ├── programB
│ │ └── tasks
│ │ └── main.yml
│ ├── programC
│ │ └── tasks
│ │ └── main.yml
…
`
Here is what I have tried in playbooks/all-programs.yml so far (here, … means the end of the YAML file):
In general the “Try something and ignore failure” approach will mask all errors, and will prevent your setup from being idempotent.
There is a reason for the failure. Find out what that is, then use that as condition to run the task.
Why not define a bunch of variables for each host/whatever and
then have the different playbooks be called, include things, and do
other things depending on what those variables tell them?
I am not sure what you mean by “prevent my setup from being idempotent” – assuming that I have (probably) written my roles to check if the changes have not already been applied before the tasks to apply changes run, should the failure of one playbook’s hosts not just remove those unreachable hosts from future plays, and fall through and continue running?
As far as reason for failure, is that not just the fact that the host does not exist in this environment?
My first thought would be to write a conditional to only “include” the playbook if the host returns a successful pong, but Ansible marks unreachable hosts as fatal errors, and once the first included playbook runs out of hosts, the entire playbook of playbooks aborts.
I could solve this by limiting the playbook to not talk to the hosts, but QA runs the playbook exactly as I run it in test, and so if I limit it in test, QA limits it in their inspection, and the inspection will fail because not all hosts were touched.
We want to do this as a check that all of our hosts are in synch; we have a playbook per system type, and we don’t want the check to fail if e.g. the only host of a given type is down (which would thus be a 100% failure of that playbook).