Score:1

How to handle host aliases in ansible

ru flag

Background: several parts of my host inventory are harvested automatically with the help of (many) scripts, mostly run out of cron. Many hosts have aliases (CNAMES, different network interfaces etc.) meaning that ssh host brings you to the same machine as ssh host_alias, and these aliases have a way to make it into the inventory and becoming immortal (because they pop up in several files) until manually found and removed (the thing also sometimes happens with manually maintained files). This has the expected effect of repeating operations several times on the same host, plus other headaches.

I could use IPs, but readability something something, and besides, hosts with multiple interfaces exist, so I do not expect the problem to entirely disappear. It would be better if this could be handled "declaratively" along the lines of

my_host_name host_aliases=foo,bar,baz

where aliases are listed in the first occurrence of my_host_name. But such a beast appears not to exists.

Am I missing something? Clever tricks to the same effect?

Cheers,

Egidijus avatar
nz flag
Surely you would only ever want to have one name for a host, otherwise web1 is also data2 and backup22 ? Depending on your infra (metal, aws, random rpis), you could go all in for "native" host finding like aws dynamic ec2 inventory.. alternatively you could bootstrap each machine with https://www.consul.io/ and have them register centrally, then have your ansible ask your consul serve for hosts (but by a single name, otherwise this is madness).
Alien Life Form avatar
ru flag
That is of course what I want, but not necessarily what I get :-) Typical case: a web hosting box foo.bar.baz is also known as www.sna.fu. I have no way of documenting that in ansible and, one time or the other, www.sna.fu will squirrel in the inventory by that name (because somebody wanted to list web sites blah, blah). Hence the script galore. (Note: my company owns the iron, so no fancyschmancy cloud procedures for us)
Egidijus avatar
nz flag
I am reluctant recommending a solution without understanding how new services "pop up", and what the lifecycle is and what is your responsibility vs the responsibilities of the "contributors" that add new vhosts. There are many ways to shave this cat
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.