Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct use of hostnames in Ansible scripts #321

Open
prasadtalasila opened this issue Dec 28, 2018 · 1 comment
Open

Correct use of hostnames in Ansible scripts #321

prasadtalasila opened this issue Dec 28, 2018 · 1 comment
Labels

Comments

@prasadtalasila
Copy link
Member

Description

Ansible has three variables, namely inventory_hostname, ansible_hostname and ansible_host for referring to hostname / IP address of a host. We need to select a consistent variable to refer to the following.

  1. AutolabJS component name (main server, load balancer, execution node1, execution node2 etc.).
  2. Machine on which an AutolabJS component gets installed.
  3. Proper settings for connection to the selected machine and the AutolabJS component for installation, configuration and updates.

Expected behavior:
Conventions are set for easy configuration, installation and update of AutolabJS across single and many systems.

Actual behavior:
There is no consistent use of variable names.

References

  1. Ansible documentation on working with inventory.
  2. Difference between inventory_hostname, ansible_host and ansible_hostname - one, two
@prasadtalasila
Copy link
Member Author

The lessons can be summarized as below.

  • inventory_hostname
    app-specific component names which match DNS strings
    Ex: ms.autolabjs.com, lb.autolabjs.com, en1.autolabjs.com etc.

  • ansible_host
    IP address to be used to connect to a remote server using SSH, can be "localhost". If this variable is not specified, then inventory_hostname shall be used for connection.
    We can use a domain name too, but the DNS resolution must be in place.

  • ansible_port
    SSH port to connect to on remove server, defaults to 22.

  • ansible_hostname
    This is the hostname of remote host learnt by Ansible using "gather facts". If gather facts is set to false, then this variable is undefined.
    We don't have control over this variable, DON'T USE IT.

auto-construction of Ansible variables in inventory

Jinja2 templates are supported in Ansible inventory too. For example,

[all:vars]
host_domain=part.one.of.very.long.internal.domain.name.com
ansible_host='{{ inventory_hostname }}.{{ host_domain }}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant