inventory

2017-02-11

ansible uses an inventory to figure out what hosts it should perform tasks on

it is a very simple .ini file, and for our purposes will be located in an inventory sub folder, one for each environment

  ▾ inventory/
    ▾ dev/ 
      hosts
    ▾ prod/ 
      hosts

the hosts in a hosts file belong to a group (denoted by []), we create 2 groups one for the host type and one for the app

[nodejsHosts]
dev-server-a

[WhanApp]
dev-server-a

for dev, and

[nodejsHosts]
prod-server-a
prod-server-b

[WhanApp]
prod-server-a
prod-server-b

for prod

ansible works with ssh and the ci server’s has ssh wired up to the target hosts (so basically ssh-copy-id ci_user@<hostname> has been executed and the vm’s has a sudo-nopasswd enabled ci_user user)

to test it you run a setup module interactive command on the ci server

ansible -i inventory/dev/hosts -u ci_user -m setup