os_network module and changing project names not working

46 views
Skip to first unread message

Michael Gale

unread,
Mar 17, 2016, 8:10:20 AM3/17/16
to Ansible Project
Hello,

    I have an ansible playbook that is responsible for creating all of the projects we have defined in our projects.yml file. 

This playbook currently:
- creates all of our projects
- adds our admin_group to the projects

I am trying to use os_network to create a default private network and subnet under each project, however the network is always created under my admin project space.

I originally had this code:
--snip--
- name: Creating Project Networks
  os_network:
    name: "{{ item.1.network.name }}"
    state: "{{ item.0.state }}"
    shared: False
    external: False
  with_subelements:
  - "{{ projects }}"
  - networks
--snip--

My credentials are currently set to the default admin account and are loaded via the OS_ environment variables by sourcing an openrc file. When I execute the above code all the networks and subnets are created under the admin tenant.

I tried using the following with a hardcoded project_name:
--snip--
- name: Creating Project Networks
  os_network:
    auth:
      username: admin
      password: my_special_password
      auth_url: http://<my_ip>:5000/v3
      project_name: testproject1
    auth_type: password
    name: "{{ item.1.network.name }}"
    state: "{{ item.0.state }}"
    shared: False
    external: False
  with_subelements:
  - "{{ projects }}"
  - networks
--snip--

However the networks are still created under the admin tenant, is it safe to assume that previous os_* modules have cached an auth token? Is there a better way to interact with multiple projects when using the os_* modules?


Thanks
Michael

David Shrewsbury

unread,
Mar 17, 2016, 2:19:10 PM3/17/16
to Ansible Project
What you're trying to do is not currently supported, but lucky for you,
a community member has already been working on this:


This also requires a new release of the shade library to support the
new project parameter.

Michael Gale

unread,
Mar 18, 2016, 4:00:12 PM3/18/16
to Ansible Project
Thanks for the info, I am looking forward to that change :)

Currently I am making it work via the following method:
--snip--
- name: Creating Project Networks
  os_network:
    name: "{{ item.0.name }}_{{ item.1.network.name }}"
    state: "{{ item.0.state }}"
    shared: False
    external: False
  environment:
    OS_PROJECT_NAME: "{{ item.0.name }}"
    OS_TENANT_NAME: "{{ item.0.name }}"
    OS_TENANT_ID: ""
--snip--

Changing the OS_ environment vars for this task seem to work, I wouldn't attempt to try anything complicated with this approach. However it is meeting my needs of adding some defaults to newly created projects.

Michael
Reply all
Reply to author
Forward
0 new messages