I want to refactor the following vars file/playbook pair, to avoid hard-coding the app name in the value for log_dir
attributes.
---
# some-role-vars.yml
some_role_config:
- name: app1
log_dir: "/var/log/app1/app1.log"
- name: app2
log_dir: "/var/log/app2/app2.log"
- name: app3
log_dir: "/var/log/app3/app3.log"
# some-playbook.yml
- hosts: all
become: True
gather_facts: True
vars_files:
- some-role-vars.yml
roles:
- role: some-role
config: "{{ some_role_config }}"
Other than using set_fact
in a way similar to this, what other approaches (best practices/conventions) are available?
- name: Set some_role_config
set_fact:
some_role_config: "{{ some_role_config|default([]) + [ {'name': item, 'path': '/var/log/' + item + '/' + item + '.log' } ] }}"
with_items:
- app1
- app2
- app3