Ansible with_items no se repite

Ansible with_items no se repite

Creo que he estado en esto demasiado tiempo, pero durante toda mi vida no puedo entender por qué mi segundocon_elementosno está en bucle como el primero. Ya intenté usar unjson_querycomo en la primera tarea, que no ayudó.

Tarea:

- name: Set backing_lunuuid
  set_fact:
    backing_lunuuid: "{{ item | json_query('guest_disk_info.*.backing_lunuuid') }}" 
  with_items: " {{ rdm_jsondata.results }}" 

- debug:
    msg: " {{ backing_lunuuid }}" 

- name: Remove leading and trailing backing_lunuuid to set disk.UUID  
  set_fact:
    rdm_uuid: "{{ item[10:-12] }}"
  with_items: " {{ backing_lunuuid }}" 

- debug:
    msg: " {{ rdm_uuid }}" 

Primera salida de depuración (para backing_lunuuid):

    TASK [debug] ********************************************************************************************************************************************************************************************
ok: [localhost] => {
    "msg": " ['0200110000600507681081007e1800000000000053323134352020', '02000f0000600507681081007e1800000000000051323134352020', '0200150000600507681081007e1800000000000059323134352020', '0200130000600507681081007e1800000000000055323134352020', '0200140000600507681081007e1800000000000056323134352020', '0200240000600507681081007e1800000000000057323134352020', '0200420000600507681081007e1800000000000058323134352020', '0200100000600507681081007e1800000000000052323134352020', '0200120000600507681081007e1800000000000054323134352020']"

Segunda salida de depuración (para rdm_uuid), que no se repite como la primera"

    TASK [Remove leading and trailing backing_lunuuid to set disk.UUID] *************************************************************************************************************************************
ok: [localhost] => (item=0200110000600507681081007e1800000000000053323134352020)
ok: [localhost] => (item=02000f0000600507681081007e1800000000000051323134352020)
ok: [localhost] => (item=0200150000600507681081007e1800000000000059323134352020)
ok: [localhost] => (item=0200130000600507681081007e1800000000000055323134352020)
ok: [localhost] => (item=0200140000600507681081007e1800000000000056323134352020)
ok: [localhost] => (item=0200240000600507681081007e1800000000000057323134352020)
ok: [localhost] => (item=0200420000600507681081007e1800000000000058323134352020)
ok: [localhost] => (item=0200100000600507681081007e1800000000000052323134352020)
ok: [localhost] => (item=0200120000600507681081007e1800000000000054323134352020)

TASK [debug] ********************************************************************************************************************************************************************************************
ok: [localhost] => {
    "msg": " 600507681081007e1800000000000054"

Cualquier ayuda sería muy apreciada.

Respuesta1

Estás sobrescribiendo rdm_uuidcada iteración del bucle. Pruebe algo como esto:

- name: Remove leading and trailing backing_lunuuid to set disk.UUID  
  set_fact:
    rdm_uuid: "{{ rdm_uuid | default([]) + [item[10:-12]] }}"
  with_items: " {{ backing_lunuuid }}" 

Editar: el primero hace lo mismo pero el último elemento rdm_jsondata.resultstiene los datos que necesita. Intenta mirar rdm_jsondata.results.

Respuesta2

Usarregex_replacecortar los elementos en una tubería

rdm_uuid: "{{ backing_lunuuid|map('regex_replace', regex, replace)|list }}"
regex: '.{10}(.*).{12}'
replace: '\1'

información relacionada