OpenStack instance deployment using Ansible
This document will help to deploy the Openstack instances using Ansible.
1. Follow the steps and configure CentOS 7 based ansible provisioning server for OpenStack.
2. Create 'rdo' directory under '/opt' directory:
# mkdir /opt/rdo
3. Create 'img-upload.yaml' under '/opt/rdo' directory and add the below content:
1. Follow the steps and configure CentOS 7 based ansible provisioning server for OpenStack.
2. Create 'rdo' directory under '/opt' directory:
# mkdir /opt/rdo
3. Create 'img-upload.yaml' under '/opt/rdo' directory and add the below content:
---
- name: Image Upload activity
hosts: localhost
tasks:
- name: Download cirros
image
get_url:
url: http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
dest:
/tmp/cirros-0.3.4-x86_64-disk.img
- name: Upload cirros
image to openstack
os_image:
name: Ansible_Demo
container_format:
bare
disk_format: qcow2
state: present
filename:
/tmp/cirros-0.3.4-x86_64-disk.img
4. Authenticate the existing OpenStack setup by sourcing its 'keystonerc_admin' file and then start the image upload process:
Now run the below command to download the image and upload to the image server.
# ansible-playbook /opt/rdo/img-upload.yaml -c local -vv
# source keystonerc_admin
Check the current image list in the image store:
# openstack image list
+--------------------------------------+------------------------------+--------+
| ID | Name | Status |
+--------------------------------------+------------------------------+--------+
| cd417aa6-6277-42f7-b8eb-1e1a8f199ff4 | Ubuntu 16.04 LTS Cloud Image | active |
+--------------------------------------+------------------------------+--------+
| ID | Name | Status |
+--------------------------------------+------------------------------+--------+
| cd417aa6-6277-42f7-b8eb-1e1a8f199ff4 | Ubuntu 16.04 LTS Cloud Image | active |
+--------------------------------------+------------------------------+--------+
# ansible-playbook /opt/rdo/img-upload.yaml -c local -vv
Using /etc/ansible/ansible.cfg as
config file
[WARNING]:
provided hosts list is empty, only localhost is available
PLAYBOOK:
img-upload.yaml
************************************************************************************************************
1
plays in /opt/rdo/img-upload.yaml
PLAY
[Image Upload activity]
************************************************************************************************************
TASK
[Gathering Facts]
************************************************************************************************************
ok:
[localhost]
TASK
[Download cirros image]
************************************************************************************************************
task
path: /opt/rdo/img-upload.yaml:5
TASK
[Upload cirros image to openstack]
************************************************************************************************************
task
path: /opt/rdo/img-upload.yaml:9
PLAY
RECAP
************************************************************************************************************
localhost :ok=3 changed=1 unreachable=0 failed=0
Once image upload is done, run the image list command again to see the new image from command line:
# openstack image list
+--------------------------------------+------------------------------+--------+
| ID | Name | Status |
+--------------------------------------+------------------------------+--------+
| be1f8c47-59ac-47ec-9797-2a0b996df30b | Ansible_Demo | active |
| cd417aa6-6277-42f7-b8eb-1e1a8f199ff4 | Ubuntu 16.04 LTS Cloud Image | active |
+--------------------------------------+------------------------------+--------+
5. Create 'instance.yaml' file under '/opt/rdo' directory and add the below content to launch the instance:
NOTE: Replace the "xxx.xxx.xxx.xxx" with correct DNS server ip for your OpenStack setup.
To deploy the instance, execute the below command from the ansible server:
# ansible-playbook /opt/rdo/Instance.yaml -c local -vv
************************************************************************************************************************
************************************************************************************************************************
************************************************************************************************************************
6. Once the instance creation is done it can be accessible directly using its floating IP 172.24.4.5 over ssh. Just need to download the 'ansible_loginkey'.
# openstack server show Ansible_Demo_Instance
# openstack image list
+--------------------------------------+------------------------------+--------+
| ID | Name | Status |
+--------------------------------------+------------------------------+--------+
| be1f8c47-59ac-47ec-9797-2a0b996df30b | Ansible_Demo | active |
| cd417aa6-6277-42f7-b8eb-1e1a8f199ff4 | Ubuntu 16.04 LTS Cloud Image | active |
+--------------------------------------+------------------------------+--------+
5. Create 'instance.yaml' file under '/opt/rdo' directory and add the below content to launch the instance:
---
- name: Ansible Demo for OpenStack Instance Deployment
hosts: localhost
vars:
validate_certs: no
tasks:
- name: Create a keypair for
current user's use
os_keypair:
state: present
name: ansible_loginkey
validate_certs:
"{{validate_certs}}"
- name: Create a private
network
os_network:
state: present
name: ansible_private_net
external: False
shared: False
validate_certs:
"{{validate_certs}}"
register: private_network
- name: Create a private subnet
os_subnet:
state: present
network_name: "{{
private_network.id }}"
name:
ansible_private_subnet
ip_version: 4
cidr: 192.168.100.0/24
gateway_ip: 192.168.100.1
enable_dhcp: yes
validate_certs:
"{{validate_certs}}"
dns_nameservers:
- xxx.xxx.xxx.xxx
register:
ansible_private_subnet
- name: Create a router
ignore_errors: yes
os_router:
state: present
name: ansible_demo_router
network: public
validate_certs:
"{{validate_certs}}"
external_fixed_ips:
- subnet: public_subnet
interfaces:
- ansible_private_subnet
- name: Create a security group
os_security_group:
state: present
name: ansible-demo-secgrp
validate_certs:
"{{validate_certs}}"
- name: security group to allow
ICMP
os_security_group_rule:
security_group:
ansible-demo-secgrp
protocol: icmp
remote_ip_prefix: 0.0.0.0/0
validate_certs:
"{{validate_certs}}"
- name: security group to allow
SSH connections
os_security_group_rule:
security_group:
ansible-demo-secgrp
protocol: tcp
port_range_min: 22
port_range_max: 22
remote_ip_prefix: 0.0.0.0/0
validate_certs:
"{{validate_certs}}"
- name: Create Ansible_Demo
Instance
os_server:
state: present
name: ansible_demo_instance
image: Ansible_Demo
flavor: m1.small
security_groups:
ansible-demo-secgrp
key_name: ansible_loginkey
validate_certs:
"{{validate_certs}}"
nics:
- net-id: "{{
private_network.id }}"
register:
ansible_demo_instance
- name: Display Ansible_Demo
instance’s Floating IP
debug:
msg: "Ansible_Demo
instance's Floating ip is {{ ansible_demo_instance.openstack.public_v4 }}"
NOTE: Replace the "xxx.xxx.xxx.xxx" with correct DNS server ip for your OpenStack setup.
To deploy the instance, execute the below command from the ansible server:
# ansible-playbook /opt/rdo/Instance.yaml -c local -vv
Using
/etc/ansible/ansible.cfg as config file
[WARNING]: provided
hosts list is empty, only localhost is available
PLAYBOOK: Instance.yaml
************************************************************************************************************************
1 plays in
/opt/rdo/Instance.yaml
PLAY [Ansible Demo for
OpenStack Instance Deployment]
TASK [Gathering Facts]
************************************************************************************************************************
ok: [localhost]
META: ran handlers
TASK [Create a keypair for
current user's use]
task path:
/opt/rdo/Instance.yaml:7
TASK [Create a private
network]
************************************************************************************************************************
task path:
/opt/rdo/Instance.yaml:13
TASK [Create a private
subnet]
************************************************************************************************************************
task path:
/opt/rdo/Instance.yaml:22
TASK [Create a router]
************************************************************************************************************************
task path:
/opt/rdo/Instance.yaml:36
TASK [Create a security
group]
************************************************************************************************************************
task path:
/opt/rdo/Instance.yaml:48
TASK [security group to
allow ICMP]
************************************************************************************************************************
task path:
/opt/rdo/Instance.yaml:53
TASK [security group to
allow SSH connections]
task path:
/opt/rdo/Instance.yaml:59
TASK [Create Ansible_Demo
Instance]
************************************************************************************************************************
task path:
/opt/rdo/Instance.yaml:68
TASK [Display Ansible_Demo
instance's Floating IP]
************************************************************************************************************************
task path:
/opt/rdo/Instance.yaml:81
ok: [localhost] => {
"msg": "Ansible_Demo instance's Floating ip is 172.24.4.5"
}
PLAY RECAP
************************************************************************************************************************
localhost :
ok=10 changed=8 unreachable=0 failed=0
6. Once the instance creation is done it can be accessible directly using its floating IP 172.24.4.5 over ssh. Just need to download the 'ansible_loginkey'.
# openstack server show Ansible_Demo_Instance
+--------------------------------+--------------------------------------------------+
| Field | Value |
+-------------------------------------+----------------------------------------------------------+
| OS-DCF:diskConfig | MANUAL |
| OS-EXT-AZ:availability_zone | nova |
| OS-EXT-SRV-ATTR:host | rdo.example.com |
| OS-EXT-SRV-ATTR:hypervisor_hostname | rdo.example.com |
| OS-EXT-SRV-ATTR:instance_name | instance-00000003 |
| OS-EXT-STS:power_state | Running |
| OS-EXT-STS:task_state | None |
| OS-EXT-STS:vm_state | active |
| OS-SRV-USG:launched_at | 2017-07-08T12:20:31.000000 |
| OS-SRV-USG:terminated_at | None |
| accessIPv4 | |
| accessIPv6 | |
| addresses | ansible_private_net=192.168.100.4, 172.24.4.5 |
| config_drive | |
| created | 2017-07-08T12:20:23Z |
| flavor | m1.small (2) |
| hostId | 02913a786afa8c7f7f9229d02a47432e6fa94bfd8b339e2e1f2bb394 |
| id | 27574b21-a06c-414a-ab24-64fa4007cf13 |
| image | Ansible_Demo (562d2536-95e4-461f-ae3a-5643cf1ec4eb) |
| key_name | ansible_loginkey |
| name | Ansible_Demo_Instance |
| progress | 0 |
| project_id | 58d0dd69f6284926a92a507a3de2badd |
| properties | |
| security_groups | name='ansible-demo-secgrp' |
| status | ACTIVE |
| updated | 2017-07-08T12:20:31Z |
| user_id | 86438308e51747ec84e8bffcd1261683 |
| volumes_attached | |
+-------------------------------------+----------------------------------------------------------+
Here to provide the floating ip, "public" should be available. Remaining components will be created at the time of deployment of the instance. No dedicated volumes will be created but as per requirement it can be done.
Comments
Post a Comment