Ansible for openstack

27 views
Skip to first unread message

Rahul Kumar

unread,
Aug 5, 2019, 3:19:19 AM8/5/19
to ansible...@googlegroups.com
Hi All,
I have provisoned one instance with following order in openstack using Ansible:
1. Download cloud image
2. upload cloud image in Openstack
3. created key pair
4. created network
5. created subnet
6. created router
7. created security group
8. created SG rule
9. created instance

and it went successfully. Now i want to remove the resources what order i should follow:
I tried 1 task and it is success
1. delete SG rule

after that i am getting stuck because anything i try to delete , it has association with some other resource.

Help me

Sebastian Meyer

unread,
Aug 5, 2019, 3:39:47 AM8/5/19
to ansible...@googlegroups.com
Hi Rahul,

everything is connected to the instance, no? You can't deprovision sec
groups, network stuff or key_pairs while they are in use.

You'll have to remove the instance first.

Regards
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 5, 2019, 3:49:10 AM8/5/19
to ansible...@googlegroups.com
Thanks Sebastien . I removed instance. but rest of all resources , i am not able to predict order, below is my playbook:
---
- name: Create a test environment
  hosts: localhost
  vars:
    cert_auth:
      ca_cert: /root/cabs12.crt
  tasks:
    - name: Remove security group rule for ping
      os_security_group_rule:
        cloud: mycloud
        ca_cert: "{{ cert_auth.ca_cert }}"
        security_group: test-security-group
        protocol: icmp
        state: absent
        remote_ip_prefix: 0.0.0.0/0

    - name: Remove security group rule for SSH
      os_security_group_rule:
        cloud: mycloud
        ca_cert: "{{ cert_auth.ca_cert }}"
        security_group: test-security-group
        protocol: tcp
        state: absent
        port_range_min: 22
        port_range_max: 22
        remote_ip_prefix: 0.0.0.0/0

    - name: Remove  instance
      os_server:
        state: absent
        ca_cert: "{{ cert_auth.ca_cert }}"
        cloud: mycloud
        name: test-instance
        image: myimage
        key_name: dump_key
        timeout: 200
        flavor: v8.m4
        network: test-network
        auto_ip: yes
        security_groups:
          - test-security-group
      register:
        my_instance
       
   - name: Remove subnet
      os_subnet:
        cloud: mycloud
        state: absent
        ca_cert: "{{ cert_auth.ca_cert }}"
        network_name: test-network
        name: test-subnet

    - name: Remove security group
      os_security_group:
        cloud: mycloud
        state: absent
        ca_cert: "{{ cert_auth.ca_cert }}"
        name: test-security-group
        description: Security group for our test instances

    - name: Remove a router
      os_router:
        cloud: mycloud
        state: absent
        ca_cert: "{{ cert_auth.ca_cert }}"
        name: test-router
        network: ext-net
        interfaces:
          - test-subnet

    - name: Remove network
      os_network:
        cloud: mycloud
        state: absent
        ca_cert: "{{ cert_auth.ca_cert }}"
        name: test-network
        external: false
        wait: yes
       
    - name: Remove new keypair from current user's default SSH key
      os_keypair:
        state: absent
        ca_cert: "{{ cert_auth.ca_cert }}"
        name: dump_key
        public_key_file: "{{ '~' | expanduser }}/.ssh/id_rsa.pub"


    - name: Remove Cloud Image from Openstack
      os_image:
        name: myimage
        container_format: bare
        cloud: mycloud
        ca_cert: "{{ cert_auth.ca_cert }}"
        disk_format: qcow2
        state: absent
        is_public: no
        filename: /root/tas/cirros-0.3.4-x86_64-disk.img
       
    - name: Remove security group
      os_security_group:
        cloud: mycloud
        state: absent
        ca_cert: "{{ cert_auth.ca_cert }}"
        name: test-security-group
        description: Security group for our test instances

--
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/3c5f570b-09ee-0344-0b26-d9bd0d588bc3%40b1-systems.de.

Dick Visser

unread,
Aug 5, 2019, 4:26:50 AM8/5/19
to ansible...@googlegroups.com
I have access to various Openstack clusters from different providers
and I found it was very much dependent on the way the cluster has been
setup, and also what version of openstack component were used.
It was hard to create a generic role/playbook that works well across
those providers.
Similarly, because of the different dependencies, destroying resources
was non-trivial, each provider was different.

Dick
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAGH8rEys2%2B0xc4w3knDQMp2Kg_-FCJToUUd0pMo3St_raBEpfw%40mail.gmail.com.



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

Rahul Kumar

unread,
Aug 5, 2019, 4:32:23 AM8/5/19
to ansible...@googlegroups.com
Hi dick
I am using Red hat distribution of Openstack.
And openstack --verison =3.19.0

Though , Currently i am just targeting one instance (and not even stack) for starting purpose and i want to use
only red hat openstack platform and no other provider.

Reply all
Reply to author
Forward
0 new messages