Reputation: 21
My Task is
- name: task name
shell: openstack floating ip create provider --format json
register: result
The output will be in below json format
{
"router_id": null,
"status": "DOWN",
"description": "",
"created_at": "2017-05-24T10:49:15Z",
"updated_at": "2017-05-24T10:49:15Z",
"floating_network_id": "923-cc77237b08e7",
"headers": "",
"fixed_ip_address": null,
"floating_ip_address": "192.*.*.*",
"revision_number": 1,
"project_id": "2709ad381fcf41c5bce673c916fded10",
"port_id": null,
"id": "c5d187elg-d269-4eae-b6ae-7d258f04983"
}
What i want to do is,get only the floating_ip_address and store it into a variable so that i can use it in another task.
Im using the below code for doing this,
- set_fact:
address: "{{ (result.stdout | from_json | selectattr('floating_ip_address') | list | first).floating_ip_address }}"
But Im getting an error
"ERROR! 'unicode object' has no attribute 'floating_ip_address'"
What is correct format to get only the ip address?
Upvotes: 1
Views: 1759
Reputation: 68469
If floating_ip_address
is not a list, but a simple key as in your input, for example:
- set_fact:
address: "{{ (result.stdout | from_json)['floating_ip_address'] }}"
Upvotes: 2