managing multi-node environments

I have environments that contain different nodes of different roles/types like: databases, webservers, load-balancers.
Sometimes I need to call every server of the same role/type, but sometimes I need to address an environment.

e.g.:

[databases]
test1.db.my.com ansible_ssh_host=192.168.1.200 ansible_ssh_user=…
test2.db.my.com ansible_ssh_host=192.168.1.201 ansible_ssh_user=…

[webservers]
test1.web.my.com ansible_ssh_host=192.168.1.300 ansible_ssh_user=…
test2.web.my.com ansible_ssh_host=192.168.1.301 ansible_ssh_user=…

[load-balancers]
test1.lb.my.com ansible_ssh_host=192.168.1.400 ansible_ssh_user=…
test2.lb.my.com ansible_ssh_host=192.168.1.401 ansible_ssh_user=…

[test1]
test1.db.my.com
test1.web.my.com
test1.lb.my.com

[test2]
test2.db.my.com
test2.web.my.com
test2.lb.my.com

So sometimes I need to run some update on all ‘webservers’, but sometimes I want to stop and reconfigure all servers in ‘test2’.

At last I need to address a specific environment and do things on different nodes iin sequence, e.g.

  • ping the ‘database’ inside
  • ‘df -h’ all the webservers
  • then ‘free -m’ all the load-balancers

How could I tell that the following playbook is only for ‘test1’ environment and I need to run the ‘databases’ part of the playbook only for the databases inside that environment?

What are the starting points or steps? Topics I should read?

Regards:
Bence

hosts: databases:&test1

^ will make the playbook target only hosts that exist in both groups
http://docs.ansible.com/intro_patterns.html#patterns

We followed the recommendation at

http://docs.ansible.com/playbooks_best_practices.html#stage-vs-production
and have separate inventory files for each distinct environment (in your case test1 and test2).

We then invoke ansible with “-i test1” or “-i test2” depending on what environment is being targeted. The ability to hit -all- webservers with one command is lost, but you usually don’t want to do that and it’s safer to update test1 before test2 (or production).

So far this has worked well.

You don't loose anything if you put both inventories in the same
directory, then you can call that directory as a 'global unified
inventory' with -i /dir/with/test1andtest2 and still address all
webservers.

Interesting!

So if, instead of having top-level files called “env1”, “env2” and “env3”, we created a “inv” folder and moved them all into there…
You’re saying we could run on just env1 with “-i inv/env1” or all envs with “-i inv”?

Will it still pull in the values from group_vars/env1 when we do the former?

Thanks, Brian

…and what if i just don’t want to declare it in the playbook?
Can I make the environment a parameter for the playbook?

hosts: “databases:&{{env}}”

or when calling the playbook:

ansible-playbook example.yml --limit test1

Regards:
Bence

  1. december 23., kedd 13:35:07 UTC+1 időpontban Brian Coca a következőt írta:

I found that:
http://stackoverflow.com/questions/18195142/safely-limiting-ansible-playbooks-to-a-single-machine

  1. december 25., csütörtök 16:41:17 UTC+1 időpontban Bence Takács a következőt írta:

Here is a detailed description of my original idea: http://rosstuck.com/multistage-environments-with-ansible/

It seems that the concept was not obvious for others either. But afer a little digging they come up with the same concept… :wink:

Regards:

Bence