Add support for IPv6 for Openstack in terraform.py via metadata (#4716)
* Add support for IPv6 for Openstack in terraform.py via metadata * document terraform.py metadata variables for openstack
This commit is contained in:
parent
4d5c4a13cb
commit
56ae3bfec2
2 changed files with 34 additions and 4 deletions
|
@ -325,6 +325,30 @@ $ ssh-add ~/.ssh/id_rsa
|
||||||
|
|
||||||
If you have deployed and destroyed a previous iteration of your cluster, you will need to clear out any stale keys from your SSH "known hosts" file ( `~/.ssh/known_hosts`).
|
If you have deployed and destroyed a previous iteration of your cluster, you will need to clear out any stale keys from your SSH "known hosts" file ( `~/.ssh/known_hosts`).
|
||||||
|
|
||||||
|
#### Metadata variables
|
||||||
|
|
||||||
|
The [python script](../terraform.py) that reads the
|
||||||
|
generated`.tfstate` file to generate a dynamic inventory recognizes
|
||||||
|
some variables within a "metadata" block, defined in a "resource"
|
||||||
|
block (example):
|
||||||
|
|
||||||
|
```
|
||||||
|
resource "openstack_compute_instance_v2" "example" {
|
||||||
|
...
|
||||||
|
metadata {
|
||||||
|
ssh_user = "ubuntu"
|
||||||
|
prefer_ipv6 = true
|
||||||
|
python_bin = "/usr/bin/python3"
|
||||||
|
}
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
As the example shows, these let you define the SSH username for
|
||||||
|
Ansible, a Python binary which is needed by Ansible if
|
||||||
|
`/usr/bin/python` doesn't exist, and whether the IPv6 address of the
|
||||||
|
instance should be preferred over IPv4.
|
||||||
|
|
||||||
#### Bastion host
|
#### Bastion host
|
||||||
|
|
||||||
Bastion access will be determined by:
|
Bastion access will be determined by:
|
||||||
|
|
|
@ -239,10 +239,16 @@ def openstack_host(resource, module_name):
|
||||||
attrs['private_ipv4'] = raw_attrs['network.0.fixed_ip_v4']
|
attrs['private_ipv4'] = raw_attrs['network.0.fixed_ip_v4']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
attrs.update({
|
if 'metadata.prefer_ipv6' in raw_attrs and raw_attrs['metadata.prefer_ipv6'] == "1":
|
||||||
'ansible_ssh_host': raw_attrs['access_ip_v4'],
|
attrs.update({
|
||||||
'publicly_routable': True,
|
'ansible_ssh_host': re.sub("[\[\]]", "", raw_attrs['access_ip_v6']),
|
||||||
})
|
'publicly_routable': True,
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
attrs.update({
|
||||||
|
'ansible_ssh_host': raw_attrs['access_ip_v4'],
|
||||||
|
'publicly_routable': True,
|
||||||
|
})
|
||||||
except (KeyError, ValueError):
|
except (KeyError, ValueError):
|
||||||
attrs.update({'ansible_ssh_host': '', 'publicly_routable': False})
|
attrs.update({'ansible_ssh_host': '', 'publicly_routable': False})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue