Reputation: 530
I'm using Ansible os_project_facts module to gather admin project id of OpenStack. This is the ansible_fact log:
ansible_facts:
openstack_projects:
- description: Bootstrap project for initializing the cloud.
domain_id: default
enabled: true
id: <PROJECT_ID>
is_domain: false
is_enabled: true
location:
cloud: envvars
project:
domain_id: default
domain_name: null
id: default
name: null
region_name: null
zone: null
name: admin
options: {}
parent_id: default
properties:
options: {}
tags: []
tags: []
Apparently, this is not a dictionary, and I can't get openstack_projects.id since it is not a dictionary. How can I retrieve PROJECT_ID and use it in other tasks?
Upvotes: 0
Views: 447
Reputation: 7340
Since the openstack_projects
facts contains single list element with a dictionary, we can use the array indexing method to get the id
, i.e. openstack_projects[0]['id']
.
You can use it directly, or use something like set_fact
:
- name: get the project id
set_fact:
project_id: "{{ openstack_projects[0]['id'] }}"
Upvotes: 1