Force ansible to apply changes on each lines of an inventory group

Viewed 46

I have a bare metal server, and I want to install multiple services on this server.

My inventory looks like that

[Mygroup]
Server port_service=9990 service_name="service1"
Server port_service=9991 service_name="service2"

When I launch my ansible job,only service 2 is installed because I have the same server in each line of my group. There is way to force ansible to take all lines of a group?

I don't want to create a group for each service

3 Answers

Q: "There is a way to force Ansible to take all lines of a group?"

A: No. There is not. In a group, the hosts shall be unique. If there are multiple hosts with the same name the last one will be taken.

Put the variables into one line e.g.

[Mygroup]
Server port_services="[9990, 9991]" service_names="['service1', 'service2']"

(and change the code).


See How to build your inventory. There is a lot of other options e.g.

[Mygroup]
Server

[Mygroup:vars]
port_services="[9990, 9991]"
service_names="['service1', 'service2']"

Another solution is to use an alias.

This solution works fine for me

[Mygroup]
service_1 ansible_host=Server port_service=9990 service_name="service1"
service_2 ansible_host=Server port_service=9991 service_name="service2"
Related