Search code examples
ansibleopenstackmulti-tenant

Source change during Openstack deployment using Ansible and Packstack


I am using a roles structure to deploy an Openstack infra and in the main.yml from the task folder I would have some tasks that should apply to one tenant and some tasks that should apply to a different tenant.

I would like to run all tasks at once even if are from different tenants. For this, I would need to specify somehow that some tasks are for tenant1 and some tasks are for tenant2.

Let's take a simple example. I am currently sourcing tenant 1 when running the Ansible tasks, but I would like that the following Ansible task to run on tenant2:

- name: Create the security group
  os_security_group:
     state: present
     name: sg_default
     description: Security group
  tags: security_group

As a first step, I have added the admin role on both tenants.

Is any option that helps me run everything at once in the main's task file even the tenants are different? Or can be this changed something from the main's yml where I am specifying the roles?


Solution

  • Found a way:

    Create a clouds.yml file from where you are running the playbook. Something like:

    clouds:
      testing:
        auth:
          auth_url: http://openstack.local:5000/v2.0
          username: admin
          password: secret
          project_name: admin
    

    Inside the function insert cloud as this:

    - name: Create the security group
      os_security_group:
         state: present 
         cloud: testing
         name: sg_default
         description: SG group
      tags: security_group