Contexte
Group vars
prometheus01 ansible_host=13.3.42.176 internal_ip=172.32.11.123 prometheus02 ansible_host=6.17.22.216 internal_ip=172.32.11.124
Rendu
Ajouter un suffix
- hosts: prometheus run_once: true tasks: - debug: msg: - "{{ groups['prometheus'] | product([':9090']) | map('join') | join(',') }}" - "{{ groups['prometheus'] | map('extract', hostvars, ['internal_ip']) | product([':9090']) | map('join') | join(',') }}"
Résultat
ansible-playbook -i inventories/prometheus playbook.add-suffix-list.yaml
TASK [debug] ********************************************************************************************************************************************
ok: [prometheus01] => {
"msg": [
"prometheus01:9090,prometheus02:9090",
"172.32.11.123:9090,172.32.11.124:9090"
]
}
Ajouter un préfix
- hosts: prometheus run_once: true tasks: - debug: msg: - "{{ ['https://'] | product(groups['prometheus']) | map('join') | join(',') }}" - "{{ ['https://'] | product(groups['prometheus'] | map('extract', hostvars, ['internal_ip'])) | map('join') | join(',') }}"
Résultat
ansible-playbook -i inventories/prometheus playbook.add-prefix-list.yaml
TASK [debug] ********************************************************************************************************************************************
ok: [prometheus01] => {
"msg": [
"https://prometheus01,https://prometheus02",
"https://172.32.11.123,https://172.32.11.124"
]
}