Inventory group not getting created when using add_host and one of the iteration of task fails.

15 views
Skip to first unread message

Bunty G

unread,
Feb 23, 2023, 2:50:29 PM2/23/23
to Ansible Development

Inventory group not getting created when using add_host and one of the iteration of task fails.

Below is the playbook

--
- hosts: localhost
  connection: local
  # become: yes
  # become_method: sudo 

  tasks:    
- set_fact:
         hosts:
           - name: "web1"
             change: "chg6556"
             num: "654"
           - name: "web2"
             num: "466"
    - add_host:
        name: "{{ item.name }}"
        groups: webs
        change: "{{ item.change}}"
        number: "{{ item.num}}"
      ignore_errors: true
      with_items: "{{ hosts }}"    

- debug:
        msg: "{{ groups }}"

Brian Coca

unread,
Mar 6, 2023, 1:11:14 PM3/6/23
to Bunty G, Ansible Development
it is not really effective until the 'next play' as modifying the
current play's data is very problematic.

--
----------
Brian Coca

Reply all
Reply to author
Forward
0 new messages