ansible/ansible — pull request #6961 by CaptTofu (2014-04-11 19:13:30+00:00)
Title: Added floating IP functionality to nova_compute

Hi!

I added the ability for a user to specify that they want a given IP, or to auto-assign a floating IP to a launched instance. Why? Well, some cloud providers, including HP Cloud and in fact, stock Nova (using devstack) with Grizzly, Havana, are set up such that when you launch an instance, you cannot get into that instance until a floating IP is assigned. This solves that issue. I introduce a similar fix into SaltCloud that is now merged and since delving into Ansible, found that the nova_compute module needs the same thing.

I simply specify:

# Creates a new VM and attaches to a network and passes metadata to the instance
- name: launch a nova instance
hosts: localhost
tasks:
- name: launch an instance
nova_compute:
state: present
login_username: username_group
login_password: redacted
login_tenant_name: username-project1
name: vm1
auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/
region_name: region-b.geo-1
image_id: 9302692b-b787-4b52-a3a6-daebb79cb498
key_name: test
wait_for: 200
flavor_id: 101
security_groups: default
floating_ip:
auto: True

and when I run this (verbose)

(python-dev)patg@ubuntu:~/code/cluster-install$ ansible-playbook -vvvv -i hosts compute.yml

PLAY [launch a nova instance] *************************************************

GATHERING FACTS ***************************************************************
REMOTE_MODULE setup
EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1397237613.78-137688590001215
&& chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1397237613.78-137688590001215 && echo $HOME/.ansible/tmp/ansible-tmp-1397237613.78-137688590001215']
PUT /tmp/tmpKNZx2U TO /home/patg/.ansible/tmp/ansible-tmp-1397237613.78137688590001215/setup
EXEC ['/bin/sh', '-c', '/usr/bin/python /home/patg/.ansible/tmp/ansible-tmp-1397237613.78-137
688590001215/setup; rm -rf /home/patg/.ansible/tmp/ansible-tmp-1397237613.78-137688590001215/ >/dev/null2>&1']
ok: [localhost]

TASK: [launch an instance] ****************************************************
REMOTE_MODULE nova_compute region_name=region-b.geo-1 security_groups=default login_username=username_group login_password=VALUE_HIDDEN auth_url=https://region-b.geo1.identity.hpcloudsvc.com:35357/v2.0/ state=present image_id=9302692b-b787-4b52-a3a6-daebb79cb498 key_name=test login_tenant_name=advanced_technology_group-project1 name=vm1
EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1397237614.2-130455430804821
&& chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1397237614.2-130455430804821 && echo $HOME/.ansible/tmp/ansible-tmp-1397237614.2-130455430804821']
PUT /tmp/tmpbYIfYx TO /home/patg/.ansible/tmp/ansible-tmp-1397237614.2-130455430804821/nova_compute
EXEC ['/bin/sh', '-c', '/usr/bin/python /home/patg/.ansible/tmp/ansible-tmp-1397237614.2-130455430804821/nova_compute; rm -rf /home/patg/.ansible/tmp/ansible-tmp-1397237614.2-130455430804821/ >/dev/null 2>&1'] changed: [localhost] => {"changed": true, "id": "7407b96f-2670-422e-b43d-c345e8ea7f11", "info": {"OS-EXT-AZ:availability_zone": "az2", "OS-EXT-STS:power_state": 1, "OS-EXT-STS:task_state": null, "OS-EXT-STS:vm_state": "active", "accessIPv4": "", "accessIPv6": "", "addresses": {"username-network":
[{"OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:e7:95:ea", "OS-EXT-IPS:type": "fixed", "addr": "10.0.0.101", "vers
ion": 4}, {"OS-EXT-IPS-MAC:mac_addr": "fa:16:3e:e7:95:ea", "OS-EXT-IPS:type": "floating", "addr": "15.126
.238.160", "version": 4}]}, "config_drive": "", "created": "2014-04-11T17:33:35Z", "flavor": {"id": "101"
, "links": [{"href": "http://region-b.geo-1.compute.hpcloudsvc.com/10966558279755/flavors/101", "rel": "b
ookmark"}]}, "hostId": "cb776184d50b8e0f6ad84c84b9529cfdf1cb5cd451877c3e8cb9ce34", "id": "7407b96f-2670-4
22e-b43d-c345e8ea7f11", "image": {"id": "9302692b-b787-4b52-a3a6-daebb79cb498", "links": [{"href": "http:
//region-b.geo-1.compute.hpcloudsvc.com/10966558279755/images/9302692b-b787-4b52-a3a6-daebb79cb498", "rel": "bookmark"}]}, "key_name": "test", "links": [{"href": "http://region-b.geo-1.compute.hpcloudsvc.com/v2
/10966558279755/servers/7407b96f-2670-422e-b43d-c345e8ea7f11", "rel": "self"}, {"href": "http://region-b.
geo-1.compute.hpcloudsvc.com/10966558279755/servers/7407b96f-2670-422e-b43d-c345e8ea7f11", "rel": "bookmark"}], "metadata": {}, "name": "vm1", "progress": 0, "security_groups": [{"name": "default"}], "status":
"ACTIVE", "tenant_id": "11111111111", "updated": "2014-04-11T17:34:00Z", "user_id": "10794113572441"},
"private_ip": "10.0.0.101", "public_ip": "15.126.238.160", "status": "ACTIVE"}

PLAY RECAP ********************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0