# Refactoring variables to avoid hard coding the same value over and over again

**URL:** <https://forum.ansible.com/t/refactoring-variables-to-avoid-hard-coding-the-same-value-over-and-over-again/25786>\
**Category:** Ansible Project\
**Created:** [October 20, 2017, 12:10am UTC](https://forum.ansible.com/t/refactoring-variables-to-avoid-hard-coding-the-same-value-over-and-over-again/25786 "2017-10-20T00:10:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Behrang](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@Behrang](https://forum.ansible.com/u/Behrang)\
**Post date:** [October 20, 2017, 12:10am UTC](https://forum.ansible.com/t/refactoring-variables-to-avoid-hard-coding-the-same-value-over-and-over-again/25786/1 "2017-10-20T00:10:38Z")

</div>

I want to refactor the following vars file/playbook pair, to avoid hard-coding the app name in the value for `log_dir` attributes.

```auto

---
# 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"

```

```auto

# 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?

```auto

- 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

```
