I am using a Linux VM managed many Linux boxes (in a different domain), I find it annoying to use FQDN for each individual servers, because our internal domain name is very long.
For example
[web]
serve1.part.one.of.very.long.internal.domain.name.com
anotherserver.part.one.of.very.long.internal.domain.name.com
Is there a way to specify a default domain for groups of servers in inventory? I tried adding andible_domain
variable in inventory file as a variable but did not work.
Once your inventory is defined, you use patterns to select the hosts or groups you want Ansible to run against. The default location for inventory is a file called /etc/ansible/hosts . You can specify a different inventory file at the command line using the -i <path> option.
You can specify a different inventory file using the -i <path> option on the command line. Not only is this inventory configurable, but you can also use multiple inventory files at the same time (explained below) and also pull inventory from dynamic or cloud sources, as described in Dynamic Inventory.
If the location given to -i in Ansible is a directory (or as so configured in ansible. cfg ), Ansible can use multiple inventory sources at the same time. When doing so, it is possible to mix both dynamic and statically managed inventory sources in the same ansible run.
By default Ansible will assume that your inventory_hostname
(the first string on the line in the inventory file) is what you would use to connect to that.
You can, however, always override this by using ansible_host
(or ansible_ssh_host
in older versions) which is useful if for some reason that's not the FQDN of the host or the domain for the host isn't in your DNS search domain list.
So you could do something like this:
[all:vars]
host_domain=part.one.of.very.long.internal.domain.name.com
ansible_host="{{inventory_hostname}}.{{host_domain}}"
[web]
server1
anotherserver
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With