host iterate on host rather on groups

5 views
Skip to first unread message

Marc Monlouis

unread,
Aug 28, 2023, 9:34:21 AM8/28/23
to Ansible Project
Why this is marked as abuse? It has been marked as abuse.
Report not abuse
Hello,

I tring to write a role that manage installation of application modules on servers.
All modules must be installed in one time: installtion command takes list of modules to install.

My inventory file  list all servers that must receive a module (module are groups) =>

module1:
  hosts:
    host_1.xxx.com:
    host_2.xxx.com:

module2:
  hosts:
    host_1.xxx.com:

module3:
    host_2.xxx.com:

But by default playbook iterate on groups not hosts.
1) i got host_1.xxx.com and  host_2.xxx.com for installtion module1
2) i got host_1.xxx.com:for installtion of module2
3) i got host_2.xxx.com for installtion of module3

But i want:
1)
host_1.xxx.com for installation of module1 and module2
2)
host_2.xxx.com for installation of module1 and module3

note:  organize by group is important because some conifguration's informations are passed to host_1.xxx.com about  host_2.xxx.com modules and vice versa.

How can iterate on hosts and run install command with list of groups listed in inventory.
In other words i must iterate by host not by groups.

How to do that ?

Many thanks in andvance for any help



Todd Lewis

unread,
Aug 28, 2023, 2:52:31 PM8/28/23
to ansible...@googlegroups.com, Marc Monlouis, uto...@gmail.com
It's going to be something close to the following. No loops necessary.
Since I don't know what your module installation task looks like, I just
made one up and wrapped it inside a debug task.
---
- name: Install modules on hosts matching module groups
  hosts: module_*
  tasks:
    - name: Install modules by host's groups
      ansible.builtin.debug:
        msg: |
          - name: Module install task
            module_installer:
              modules: "{{ modules }}"
      vars:
        modules: "{{ group_names | select('match', 'module_.*') }}"

On 8/28/23 4:52 AM, Marc Monlouis wrote:
Hello,

I tring to write a role that manage installation of application modules on servers.
All modules must be installed in one time: installtion command takes list of modules to install.

My inventory file  list all servers that must receive a module (module are groups) =>

module1:
  hosts:
    host_1.example.com:
    host_2.example.com:

module2:
  hosts:
    host_1.example.com:

module3:
    host_2.example.com:

But by default playbook iterate on groups not hosts.
1) i got host_1.example.com and  host_2.example.com for installtion module1
2) i got host_1.example.com:for installtion of module2
3) i got host_2.example.com for installtion of module3

But i want:
1)
host_1.example.com for installation of module1 and module2
2)
host_2.example.com for installation of module1 and module3

note:  organize by group is important because some conifguration's informations are passed to host_1.example.com about  host_2.example.com modules and vice versa.

How can iterate on hosts and run install command with list of groups listed in inventory.
In other words i must iterate by host not by groups.

How to do that ?

Many thanks in andvance for any help



--
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-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/988752b8-fb76-45c1-927f-7bd917c27c81n%40googlegroups.com.

-- 
Todd
Reply all
Reply to author
Forward
0 new messages