![Realmente lento al convertir host vars a archivo env con ansible](https://rvso.com/image/768904/Realmente%20lento%20al%20convertir%20host%20vars%20a%20archivo%20env%20con%20ansible.png)
Tengo la siguiente tarea en ansible:
- name: Set env vars
lineinfile:
path: "~/.env"
mode: 0600
create: yes
line: "{{ item.key|upper }}=\"{{ item.value }}\""
regexp: "^{{ item.key|upper }}="
loop: "{{ env_file |dict2items }}"
Está creando el .env
archivo línea por línea pero es REALMENTE lento. ¿Existe una mejor manera?
El archivo .yml se ve así:
env_file:
key1: "value1"
key2: "value2"
El archivo resultante tiene el formato:
KEY1="value1"
KEY2="value2"
Cada línea tarda unos 20 segundos en procesarse y realmente suma.
Respuesta1
Intente usar el template
módulo y escribir un archivo Jinja2. Tiende a ser más rápido que lineinfile
cuando se trata de bucles.