Acceso a linux con certificado autofirmado
30 de marzo de 2023Comandos útiles PosgreSQL
11 de mayo de 2023EJEMPLO 1:
domains:
erp:
address: erp.mycompany.com
crm:
address: crm.mycompany.com
git:
address: git.mycompany.com
tasks:
- name: Print phone records
debug:
msg: "{{ item.value.address }}"
with_dict: "{{ domains }}"
# I can still access a given domain by its name when needed like so:
{{ domains.erp.address }}
EJEMPLO 2:
domains:
- erp: erp.mycompany.com
- crm: crm.mycompany.com
- git: git.mycompany.com
- name: Print domains
debug:
msg: test {{ item }}
with_items:
- "{{ domains }}"
EJEMPLO 3:
- hosts: localhost
vars:
domains:
- name: erp
address: erp.mycompany.com
- name: crm
address: crm.mycompany.com
- name: git
address: git.mycompany.com
tasks:
- name: Print phone records
debug:
msg: "{{ item.address }}"
with_items: "{{ domains }}"
EJEMPLO 4:
port:
abc:
- server1
- server2
abc_port:
- 22
- 34
cde:
- server3
- server
cde_port:
- 122
- 343
- set_fact:
dest_port: []
- set_fact:
dest_port: "{{ dest_port + item.0|
product(item.1)|
map('join', ':')|
list }}"
loop: "{{ _dest|zip(_port) }}"
vars:
_d: "{{ dest|d('') }}"
_dest_keys: "{{ (_d|length > 0)|ternary(_d.split(','), []) }}"
_port_keys: "{{ _dest_keys|product(['_port'])|map('join')|list }}"
_dest: "{{ _dest_keys|map('extract', port)|list }}"
_port: "{{ _port_keys|map('extract', port)|list }}"
gives...
dest_port:
- server1:22
- server1:34
- server2:22
- server2:34
- server3:122
- server3:343
- server:122
- server:343
Mas info:
https://blog.learncodeonline.in/everything-about-ansible-loops