If the problem is that some hosts are not available, I would address that
by simply limiting the playbook to not talk to those hosts:

https://docs.ansible.com/ansible/latest/user_guide/intro_patterns.html

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.

Dick

On Fri, 19 Jul 2019 at 04:52, Kedwin Chen <kedwinc...@gmail.com> wrote:

> 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):
> # Attempt 1
> ---
> - name: Run playbook for ProgramA
>   import_playbook: "{{ playbook_dir }}/programX.yml"
>   ignore_errors: yes
>
> - name: Run playbook for ProgramB
>   import_playbook: "{{ playbook_dir }}/programY.yml"
>   ignore_errors: yes
>
> ...
>
>
> ######
>
> # Attempt 2
> ---
> - name: Run playbook for ProgramA
>   include: "{{ playbook_dir }}/programA.yml"
>
> - name: Run playbook for ProgramB
>   include: "{{ playbook_dir }}/programB.yml"
> ...
>
>
> ######
>
> # Attempt 3
> ---
> - name: Run playbook for ProgramA
>   hosts: localhost
>   tasks:
>     - include: "{{ playbook_dir }}/programA.yml"
>
> - name: Run playbook for ProgramB
>   hosts: localhost
>   tasks:
>     - include: "{{ playbook_dir }}/programB.yml"
> ...
>
>
> ######
>
> # Attempt 4
> ---
> - name: Run all playbooks in a block
>   hosts: localhost
>   tasks:
>       - name: Try ProgramA playbook
>         block:
>             - name: "playbook for programA"
>               import_playbook: "{{ playbooks_dir }}/programA.yml"
>         rescue:
>             - debug:
>                 msg: "programA manipulation playbook failed"
>         ignore_errors: yes
>
>       - name: Try ProgramB playbook
>         block:
>             - name: "playbook for programB"
>               import_playbook: "{{ playbooks_dir }}/programB.yml"
>         rescue:
>             - debug:
>                 msg: "no programB"
>         ignore_errors: yes
> ...
>
>
> ######
>
> # Attempt 5: Copy contents of *program[A-Z].yml* playbooks into master
> playbook *all-programs.yml*
> ---
> - name: Run role of ProgramA for required hosts
>   hosts: hostA,hostC,groupB
>   gather_facts: no
>   strategy: free
>   roles:
>     - programA
>
> - name: Run role of ProgramB for required hosts
>   hosts: hostD,groupW
>   gather_facts: no
>   strategy: free
>   roles:
>     - programB
> ...
>
>
>
> Running with the following command line for each attempt above yields:
> ansible-playbook --ask-vault-pass -i /path/to/hosts -e
> "playbook_dir=/path/to/playbooks" /path/to/playbooks/all-programs.yml
>
> # Attempts 1-3:
>
> PLAY [Run playbook for Program[A|B] *********************
>
> TASK [(subtask of other_role)] **************************
> fatal: [hostA-Z]: UNREACHABLE! => {"changed: false", ...}
>
> NO MORE HOSTS LEFT **************************************
>     to retry, use: --limit @/path/to/retry
>
> #########################################################
>
> # Attempt 4:
>
> PLAY [Run all playbooks in a block] *********************
>
> TASK [Gathering Facts] **********************************
> ok: [localhost]
>
> TASK [playbook for programA] ****************************
> fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "",
> "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the
> exact error", "rc": 0}
> ...ignoring
>
> TASK [playbook for programB] ****************************
> fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "",
> "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the
> exact error", "rc": 0}
> ...ignoring
>
> From above, what might be the module failure being referred to?
>
> General layout/schema of *playbooks/program[A-Z].yml* (here, ... means
> the end of the YAML file):
> # playbooks/programA.yml
> ---
> - name: Run role of ProgramA for required hosts
>   hosts: hostA,hostC,groupB
>   gather_facts: no
>   strategy: free
>   roles:
>     - programA
> ...
>
> # playbooks/programB.yml
> ---
> - name: Run role of ProgramY for required hosts
>   hosts: hostD,groupW
>   gather_facts: no
>   strategy: free
>   roles:
>     - programB
> ...
>
> General layout/schema of *roles/program[A-Z]/tasks/main.yml* (here, ...
> means the end of the YAML file):
> ---
> - name: Role for ProgramA
>   include_role:
>     name: other_role
>   vars:
>     var1: something
>     var2: somethingElse
> ...
>
> Thank you for taking your time to read this post.
> Any assistance would be appreciated.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/6776ba24-a467-40d3-ac90-90d1fae41539%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/6776ba24-a467-40d3-ac90-90d1fae41539%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
-- 
Sent from a mobile device - please excuse the brevity, spelling and
punctuation.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAL8fbwMRnAVNzU6QEaUdwoMZreM5bU3MmEenwF3BHW-d5RJmHQ%40mail.gmail.com.

Reply via email to