@ -171,28 +173,32 @@ Now to the fun part. We create a playbook to create our infrastructure we call i
---
---
- name: provision our VMs
- name: provision our VMs
hosts: cloud-vm
hosts: cloud-vm
connection: local
tasks:
tasks:
- name: ensure VMs are created and running
- name: ensure VMs are created and running
cs_instance:
local_action:
module: cs_instance
name: "{{ inventory_hostname_short }}"
name: "{{ inventory_hostname_short }}"
template: Linux Debian 7 64-bit 20GB Disk
template: Linux Debian 7 64-bit 20GB Disk
service_offering: "{{ cs_offering }}"
service_offering: "{{ cs_offering }}"
state: running
state: running
- name: ensure static NATs
local_action:
module: cs_staticnat
vm: "{{ inventory_hostname_short }}"
ip_address: "{{ public_ip }}"
when: public_ip is defined
- name: ensure firewall ports opened
- name: ensure firewall ports opened
cs_firewall:
local_action:
module: cs_firewall
ip_address: "{{ public_ip }}"
ip_address: "{{ public_ip }}"
port: "{{ item.port }}"
port: "{{ item.port }}"
cidr: "{{ item.cidr | default('0.0.0.0/0') }}"
cidr: "{{ item.cidr | default('0.0.0.0/0') }}"
with_items: cs_firewall
with_items: cs_firewall
when: public_ip is defined
when: public_ip is defined
- name: ensure static NATs
In the above play we defined 3 tasks and use the group ``cloud-vm`` as target to handle all VMs in the cloud but instead SSH to these VMs, we use ``local_action`` to execute the API calls locally from our workstation.
In the above play we defined 3 tasks and use the group ``cloud-vm`` as target to handle all VMs in the cloud but instead SSH to these VMs, we use ``connetion=local`` to execute the API calls locally from our workstation.
In the first task, we ensure we have a running VM created with the Debian template. If the VM is already created but stopped, it would just start it. If you like to change the offering on an exisiting VM, you must add ``force: yes`` to the task, which would stop the VM, change the offering and start the VM again.
In the first task, we ensure we have a running VM created with the Debian template. If the VM is already created but stopped, it would just start it. If you like to change the offering on an exisiting VM, you must add ``force: yes`` to the task, which would stop the VM, change the offering and start the VM again.
@ -246,59 +252,68 @@ The playbook looks like the following:
In the first play we setup the security groups, in the second play the VMs will created be assigned to these groups. Further you see, that we assign the public IP returned from the modules to the host inventory. This is needed as we do not know the IPs we will get in advance. In a next step you would configure the DNS servers with these IPs for accassing the VMs with their DNS name.
In the first play we setup the security groups, in the second play the VMs will created be assigned to these groups. Further you see, that we assign the public IP returned from the modules to the host inventory. This is needed as we do not know the IPs we will get in advance. In a next step you would configure the DNS servers with these IPs for accassing the VMs with their DNS name.