Just as with ini formatted inventories, if you want to use the same IP or
hostname for 2 different "hosts", you need to create an alias for them, and
specify the hostname using ansible_host (ansible_ssh_host for versions
before v2)

An ini would look like:

host1 ansible_host=example-0.com ansible_port=22
host2 ansible_host=example-0.com ansible_port=9001

On Wed, Mar 30, 2016 at 9:23 AM, <[email protected]> wrote:

>
> Hi,
>
> I'm currently setting up two VMs that are accessible behind a single
> domain name but on different ports. I cannot figure
> out how to specifiy host-vars seperately for each host. My aim is to allow
> ansible to SSH into each of these machines; I'm not currently
> using hostvars for anything else.
>
> If I had two machines accessible on different ports and different domains
> - example-1.com:22 and example-2.com:9001 - I would produce this dynamic
> inventory JSON output:
>
> {
>  "mymachines": {
>  "hosts": [
>  "example-1.com",
>  "example-2.com"
>  ],
>  "hostvars": {
>  "example-1.com": {
>  "ansible_port": "22"
>  },
>  "example-2.com": {
>  "ansible_port": "9001"
>  }
>  }
>  }
> }
>
>
> However, there is no analogue for different hosts with the same domain
> name:
>
> {
>  "mymachines": {
>  "hosts": [
>  "example-0.com",
>  "example-0.com",
>  ],
>  "hostvars": {
>  "example-0.com": {
>  "ansible_port": "22"
>  },
>  ??: {
>  "ansible_port": "9001"
>  }
>  }
>  }
> }
>
>
> I cannot specify the domain-names alongside their ports
>
>
> {
>  "mymachines": {
>  "hosts": [
>  "example-0.com:22",
>  "example-0.com:9001",
>  ]
>  }
> }
>
>
> as Ansible passes the entire host to OpenSSH without using the -p
> argument, which means the host never resolves. It seems
> to run code equivalent to the following
>
>  ssh [email protected]:9001            # BAD
>
>
> not
>
>  ssh [email protected] -p 9001         # GOOD
>
>
> Do you have any advice for how I can create a dynamic inventory that
> allows SSH access to machines with the same domain name
> but different ports? I'll post more information if needed.
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/5e22f878-912b-4b6a-8625-1cb93769382f%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/5e22f878-912b-4b6a-8625-1cb93769382f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Matt Martz
@sivel
sivel.net

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAD8N0v_pJTGp_30fpXG3W%3DS88wgczqVT1N_zD7aQ7cSsufDyMg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to