0

I'm having trouble defining an alias for my MySQL database in my inventory file in ansible. I can easily create one for my EC2 instance by using.:

ansible_ssh_host
ansible_ssh_port
ansible_ssh_user

Like this:

[webserver]
some-hostname ansible_ssh_host=some-subdomain-of-amazon

But it doesn't use ssh to connect to the database instance. How do I create an alias for that group

[databases]
some-hostname ansible_mysql_host=some-subdomain-of-amazon

I can't seem to find anything on this in the documentation.

// Ulrik McArdle

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189

1 Answers1

0

The names you provide in ansible hosts files are not known to DNS. They are not CNAMES. Thus, you can only refer to them using ansible tools (e.g. ansible and ansible-playbook).

The ansible_ssh_host, ansible_ssh_port and ansible_ssh_user and Ansible keywords you can use to tell ansible tools 'hey, host foo has this ip, and you can connect via ssh on port ansible_ssh_portn, etc... They just have no meaning outside ansible.

This being said, ansible_mysql_host of course is not a valid keyword. So I don't really know what you are trying to achieve here, but if you need to adress your mysql server using a DNS name (which I would not really recommend depending on the driver you're using), you have to use a real DNS entry, that can be resolved from your clients.

An option is to add a name in your client's /etc/hosts file, or create a Route53 entry using the route53 ansible module.

leucos
  • 17,661
  • 1
  • 44
  • 34
  • I know they can not be used outside Ansible. It's because I would like to use the host name to create the host_vars folder or am I missing something. The endpoints in AWS is very long and it would be nice to shorten them with an alias. – Ulrik McArdle Jul 23 '15 at 10:34