3 ms·
Presumably you'll need to iterate over hosts anyway, so why not move directly towards your automation tools' (ansible, chef, puppet, etc) host inventory and not
by thezilch 12y ago
Presumably you'll need to iterate over hosts anyway, so why not move directly towards your automation tools' (ansible, chef, puppet, etc) host inventory and not fuss with DNS...
/etc/ansible/{dev,test,stage,prod}-hosts
[nyc-dns]
10.0.1.1
10.0.2.1
[nyc-web]
10.0.1.21
10.0.2.21
[nyc-db]
10.0.1.201
10.0.2.201
[nyc:children]
nyc-dns
nyc-web
nyc-db
[lax-dns]
10.0.1.1
10.0.2.1
[lax-web]
10.0.1.21
10.0.2.21
[lax-db]
10.0.1.201
10.0.2.201
[lax:children]
lax-dns
lax-web
lax-db
[dns:children]
nyc-dns
lax-dns
[web:children]
nyc-web
lax-web
[db:children]
nyc-db
lax-db
- e_proxus 12y agoJust started out with Ansible. How do you efficiently SSH into all these hosts by name instead of IP?
- thezilch 12y agoAt the low level, Ansible has the ability to execute ad-hoc [0] modules [1] against any combination of hosts defined. In my host(s) inventory above, you can execute ad-hoc modules against just nyc-web, lax-web, web(against nyc and lax), or whatever suites your needs or you've defined a host group for in your inventory. Report, using the "command" module, free memory on all "nyc-web" hosts in our "prod-hosts": ansible -i prod-hosts nyc-web -m command -a 'free -m' More often, we'll want to have Ansible playbooks [2] that take our hosts and assign roles. Briefly on the topic, we might have a "common" role that deals with updating our package manager, checking/upgrading packages that every machine should have (eg. ssh, ntp, etc), and ensuring certain processes are running. Second, we might have a "web" role that is similar to "common" but dealing with web-server specific packages, configs, etc. As to keep it brief, we'll skip how the roles are setup, but here's our "web" playbook (web.yml), and find that we've defined the hosts [group] to execute against -- all hosts under our "web" group in the hosts inventory. --- - hosts: web remote_user: web-user roles: - common - web Which we'll execute with: ansible-playbook -i prod-hosts web.yml Maybe you only want to hit nyc-web and not all web hosts? The following will take the intersection of the playbook's hosts "web" and the "limit" hosts "nyc". ansible-playbook -i prod-hosts web.yml --limit nyc Or maybe you know the one IP you want to hit. The ":&" syntax is a logic AND to find only the nyc 10.0.2.21, because we also have one in LAX. If your IP layout, then simply a "--limit 10.0.2.21" would do. ansible-playbook -i prod-hosts web.yml --limit 'nyc:&10.0.2.21' [0] http://docs.ansible.com/intro_adhoc.html http://docs.ansible.com/intro_adhoc.html [1] http://docs.ansible.com/modules.html http://docs.ansible.com/modules.html [2] http://docs.ansible.com/playbooks_intro.html http://docs.ansible.com/playbooks_intro.html
- e_proxus 12y agoAh, cool. That clarifies things. I take it there is no way of smoothly combining Ansible host lists with being able to use pure, old SSH?
- thezilch 12y agoAnsible will use the native OpenSSH on your box, which does enable you to use whatever is in your .ssh/config -- jump hosts, controlpersist, kerberos, etc