Ansible For Openstack

48 views
Skip to first unread message

Rahul Kumar

unread,
Jul 31, 2019, 3:37:12 AM7/31/19
to ansible...@googlegroups.com
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://<host>:<Port>/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:
---
- name: Create a test environment
  hosts: localhost
  tasks:
    - name: create network
      os_network:
        cloud: mycloud
        state: present
        name: test-network
        external: false
        wait: yes
---------------------
------
But i am resulting in error:
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Cloud mycloud was not found."}.
Notice clouds.yaml and Main Playbook is in same location.

Thanks
Rahul 

Dick Visser

unread,
Jul 31, 2019, 5:26:45 AM7/31/19
to ansible...@googlegroups.com
You are using the literal string 'cloud'.
Change that entry in the os_network task to:

cloud: "{{ mycloud }}"
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAGH8rEzmMwBjGVa31CA5Ffj60imd_7WQ6MFCm6EUuUP2ve_YEA%40mail.gmail.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Rahul Kumar

unread,
Jul 31, 2019, 6:04:41 AM7/31/19
to ansible...@googlegroups.com
Thanks Dick. It worked, I forgot this by mistake.

Rahul Kumar

unread,
Aug 1, 2019, 4:03:33 AM8/1/19
to ansible...@googlegroups.com
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 }}"

Dick Visser

unread,
Aug 1, 2019, 4:21:00 AM8/1/19
to ansible...@googlegroups.com
Actually, it's this:

cloud: "{{ clouds.mycloud }}"
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAGH8rExkcQeBUrPBkn2C4dy3sgP3mD6eBYBAL2dWLG69NxySaA%40mail.gmail.com.

Rahul Kumar

unread,
Aug 1, 2019, 4:26:04 AM8/1/19
to ansible...@googlegroups.com
Thanks dick but now it is complaining clouds is undefined.😔

Dick Visser

unread,
Aug 1, 2019, 5:48:17 AM8/1/19
to ansible...@googlegroups.com
You should actually include clouds.yaml in the main playbook.


--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Sebastian Meyer

unread,
Aug 1, 2019, 6:07:22 AM8/1/19
to ansible...@googlegroups.com
Hi Rahul,

On 31.07.19 09:36, Rahul Kumar wrote:
> 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

--
Sebastian Meyer
Linux Consultant & Trainer
Mail: me...@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537


-- Deutsche OpenStack Tage 2019 -- 10% Rabatt auf den Ticketpreis ----
------------------------ https://openstack-tage.de (Code DOST-B1) ----

Rahul Kumar

unread,
Aug 1, 2019, 6:20:05 AM8/1/19
to ansible...@googlegroups.com

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 .

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 ?
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.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.

Sebastian Meyer

unread,
Aug 1, 2019, 6:36:19 AM8/1/19
to ansible...@googlegroups.com
Hi Rahul,

On 01.08.19 12:19, Rahul Kumar wrote:
> 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.

Rahul Kumar

unread,
Aug 1, 2019, 6:49:59 AM8/1/19
to ansible...@googlegroups.com
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://<IP>:<Port>/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:
1. Do we need to write different playbook for deleting resources or either flip the order in the playbook as needed and make state=absent?
2. 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.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages