Je cherche à remplacer la valeur de l'élément par le nom du stockage stockageA. 1. fichier vvsets.yml.
vvsets: [{'key': 'lun.101', 'value': ['server001']}, {'key': 'lun.101', 'value': ['server001']}, {'key': 'lun.201', 'value': ['server002']}, {'key': 'lun.301', 'value': ['server003']}]
2. fichier main.yml.
tasks:
- name: A
include_vars: vvsets.yml
- set_fact:
vvsets: "{{ vvsets | combine(new_item, recursive=true) }}"
vars:
new_item: { 'value': 'storageA' }
loop: "{{ vvsets }}"
-
Sortie.
TASK [set_fact] ok: [localhost] => (item={'key': 'lun.101', 'value': ['server001']}) => { "ansible_facts": { "vvsets": { "key": "lun.301", "value": "storageA" } }, "ansible_loop_var": "item", "changed": false, "item": { "key": "lun.101", "value": [ "server001" ] } } ok: [localhost] => (item={'key': 'lun.101', 'value': ['server001']}) => { "ansible_facts": { "vvsets": { "key": "lun.301", "value": "storageA" } }, "ansible_loop_var": "item", "changed": false, "item": { "key": "lun.101", "value": [ "server001" ] } } ok: [localhost] => (item={'key': 'lun.201', 'value': ['server002']}) => { "ansible_facts": { "vvsets": { "key": "lun.301", "value": "storageA" } }, "ansible_loop_var": "item", "changed": false, "item": { "key": "lun.201", "value": [ "server002" ] } } ok: [localhost] => (item={'key': 'lun.301', 'value': ['server003']}) => { "ansible_facts": { "vvsets": { "key": "lun.301", "value": "storageA" } }, "ansible_loop_var": "item", "changed": false, "item": { "key": "lun.301", "value": [ "server003" ] } }
-
D'après les résultats obtenus, il n'y a qu'un dernier changement. Il semble que les 3 premiers soient contournés. Voici la nouvelle liste attendue.
vvsets:
- 'key': 'lun.101' 'value': ['storageA']
- 'key': 'lun.101' 'value': ['storageA']
- 'key': 'lun.201' 'value': ['storageA']
- 'key': 'lun.301' 'value': ['storageA']