It works ok.
Thank You.
hc_id: "{{ hc.json.results | json_query('[?name==`' ~ host_collection ~
'`].id') }}"
TASK [GET id HC hc2]
*********************************************************************************************************************
ok: [xxxx] => {
"hc_id": [
586
]
}
TASK [LIST INFO hc2 with UID /586]
******************************************************************************************************
ok: [ssh.sva.itbatera.ejgv.eus] => {
"hc_info.json": {
"created_at": "2018-10-18 10:47:52 UTC",
"description": null,
"host_ids": [
1280
],
"id": 586,
"max_hosts": null,
"name": "hc2",
"organization_id": 1,
"permissions": {
"deletable": true,
"editable": true
},
"total_hosts": 1,
"unlimited_hosts": true,
"updated_at": "2018-10-18 10:47:52 UTC"
}
}
El lunes, 22 de octubre de 2018, 16:58:06 (UTC+2), Alberto Jimenez Lozano
escribió:
>
> I need get a field into a json what has been generated wit uri module.
>
> This is my json that contains two hosts colections hc1 y hc2.
> I want to get the field id:693 of the host_collection hc1.
>
> "created_at": "2018-10-18 13:29:01 UTC",
> "description": null,
> "id": 693,
> "max_hosts": null,
> "name": "hc1",
> "organization_id": 1,
> "permissions": {
> "deletable": true,
> "editable": true
> },
> "total_hosts": 0,
> "unlimited_hosts": true,
> "updated_at": "2018-10-18 13:29:01 UTC"
> },
> {
> "created_at": "2018-10-18 13:29:04 UTC",
> "description": null,
> "id": 696,
> "max_hosts": null,
> "name": "hc2",
> "organization_id": 1,
> "permissions": {
> "deletable": true,
> "editable": true
> },
> "total_hosts": 0,
> "unlimited_hosts": true,
> "updated_at": "2018-10-18 13:29:04 UTC"
> },
>
> My playbook is this, but it fails.
>
> - name: GET consulta api satellite
> uri:
> url: "https://xxxxxx/katello/api/host_collections/"
> user: "{{user}}"
> password: "{{password}}"
> method: GET
> return_content: yes
> force_basic_auth: yes
> validate_certs: no
> headers:
> Content-Type: "application/json"
> status_code: [200,201,202,204,301,401]
> register: hc
>
> - name: GET ID d HC
>
> debug:
> var="hc.json.results.[?name=='hc1'].id"
>
>
>
> When I execute de playbook, it appears the next error:
>
> TASK [GET ID del HC]
> *******************************************************************************************************************************************************************************
> fatal: []: FAILED! => {}
>
> MSG:
>
> template error while templating string: unexpected char u'?' at 19. String:
> {{hc.json.results.[?name=='hc1'].id}}
> to retry, use: --limit
> @/awx/scripts/sat_uri/mb_get_host_collection.retry
>
> If I put this option, go OK.
>
> - name: GET ID del HC
> debug:
> var=hc.json.results[0].id
>
>
> **TASK [GET ID del HC]
> *******************************************************************************************************************************************************************************
> ok: [] => {
> "hc.json.results[0].id": "693"
> }**
>
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/531d0ae2-69c0-480d-a3a3-539eedfe24ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.