Hi All,
I am trying to create Openstack instances using Ansible for Openstack.
I have clouds.yaml as below:
clouds:
mycloud:
auth:
auth_url: https://:/v3
project_name: mycloud
username: mycloud
project_domain_name: Default
user_domain_name: Default
password: mycloudpwd
region_name: regionOne
interface: public
identity_api_version:
and Main Playbook is as below:
You are using the literal string 'cloud'.
Change that entry in the os_network task to:
cloud: "{{ mycloud }}"
Thanks Dick. It worked, I forgot this by mistake.
sorry to come back Dick. It is still not working from clouds.yaml
“msg”: “The task includes an option with an undefined variable. The error was: ‘mycloud’ is undefined\n\nThe error appears to be in ‘/root/tas/simpledemo/Main-Playbook.yaml’: line 5, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: create network\n ^ here\n”
Though i defined: cloud: “{{ mycloud }}”
Actually, it's this:
cloud: "{{ clouds.mycloud }}"
Thanks dick but now it is complaining clouds is undefined.
You should actually include clouds.yaml in the main playbook.
Hi Rahul,
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Cloud mycloud was
not found."}.
Notice clouds.yaml and Main Playbook is in same location.
from the module docs:
Auth information is driven by openstacksdk, which means that values
can come from a yaml config file in /etc/ansible/openstack.yaml,
/etc/openstack/clouds.yaml or ~/.config/openstack/clouds.yaml
Sebastian
Thanks Sebastien and Dick.
Yes , clouds.yaml can be kept in /etc/openstack/clouds.yaml or ~/.config/openstack/clouds.yaml but not in current
working directory (where playbook resides).
Also we can reference the named cloud directly and no need of clouds.mycloud variables etc.
I directly used like cloud: mycloud and it worked while keeping my clouds.yaml in /etc/openstack/clouds.yaml
My complete instance got created (with network ,subnet,SG,Router etc).
I have below question to both experts dick and sebastien .
- whatever resources(net,subnet,sg,router etc) are provisioned as part of this single instance creation , lets say i want to clear all those resources in one shot , how can i do this ?
- Does order of tasks matter in playbook. For example: To create instance , we need network , so first we will provision network and then other dependent resources.
Hi Rahul,
1. whatever resources(net,subnet,sg,router etc) are provisioned as part of
this single instance creation , lets say i want to clear all those
resources in one shot , how can i do this ?
Each module (os_server, os_network ...) should only create the specified
resource. For deprovisioning set the state to absent. One exception
would be e.g. a floating IP automatically assigned to the instance. That
IP isn't assigned anymore afterwards, but still created.
2. Does order of tasks matter in playbook. For example: To create instance
, we need network , so first we will provision network and then other
dependent resources.
Order matters, yes. Playbooks are run from top down, so the first task
in the list is executed first. Beware that you need a different order
for creation and destruction, afaik you cant remove a network, if theres
still an instance on it.
Thanks much Sebastien,
Good inputs.
I tried same playbook by making state = absent and got error as expected as below:
fatal: [localhost]: FAILED! => {“changed”: false, “msg”: “ConflictException: 409: Client Error for url: https://:/v2.0/networks/c4e67037-e32d-4e06-b0ba-7c07f6e1ec63.json, Unable to complete operation on network c4e67037-e32d-4e06-b0ba-7c07f6e1ec63. There are one or more ports still in use on the network.”}
So again some questions:
- Do we need to write different playbook for deleting resources or either flip the order in the playbook as needed and make state=absent?
- I tried this just to create 1 nova instnace . Assume we have multiple resources and we need to make sure right resource is attached to particular one.
For example:
Assume 2 resources:
- name: Create Networks
os_network:
name: “{{ item.name }}”
state: present
external: false
wait: yes
with_items: “{{ networks }}”
os_server:
name: “{{ prefix }}-{{ item.name }}”
state: present
key_name: “{{ item.key }}”
availability_zone: “{{ item.availability_zone }}”
nics: “{{ item.nics }}”
image: “{{ item.image }}”
flavor: “{{ item.flavor }}”
with_items: “{{ servers }}”
register: “os_hosts”
Assume network is need to provision instance . Now say we have multiple instances and multiple networks .Which we can define using networks and servers variables as shown in above snippet.
How do i ensure that one particular network is assigned to particular instance? do we need to manage this at
variables side defination only or is there any better way to handle same in playbook code?
Its just scaling use case when we have multiple resources and we want that expected resource is attached to right one.