# multiple entries for a variable

**URL:** <https://forum.ansible.com/t/multiple-entries-for-a-variable/38007>\
**Category:** Ansible Project\
**Created:** [May 18, 2023, 1:39pm UTC](https://forum.ansible.com/t/multiple-entries-for-a-variable/38007 "2023-05-18T13:39:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kathy\_L](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kathy_l/32/2652_2.png) [@Kathy\_L](https://forum.ansible.com/u/Kathy_L)\
**Post date:** [May 18, 2023, 1:39pm UTC](https://forum.ansible.com/t/multiple-entries-for-a-variable/38007/1 "2023-05-18T13:39:32Z")

</div>

In our playbook, we are making changes to the chronyd.service file. On several different Debian devices, that file is in two different locations:

/lib/systemd/system/chronyd.service  
/etc/systemd/system/chronyd.service

We call the location using:

chronyd\_systemd[system\_distro]

System\_distro is something we’ve defined with the major and minor OS versions smashed together (Debian10, CentOS7, etc.)

In the vars/main.yml file we have:

chronyd\_systemd:  
Debian10: /etc/systemd/system/chronyd.service

Debian11: /lib/systemd/system/chronyd.service

Ideally we’d like something like this:

chronyd-systemd:  
Debian11: /lib/systemd/system/chronyd.service OR /etc/systemd/system/chronyd.service

How would we go about doing this?

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [May 18, 2023, 1:55pm UTC](https://forum.ansible.com/t/multiple-entries-for-a-variable/38007/2 "2023-05-18T13:55:36Z")

</div>

> In our playbook, we are making changes to the chronyd.service file. On several different Debian devices, that file is in two different locations:
> 
> /lib/systemd/system/chronyd.service  
> /etc/systemd/system/chronyd.service
> 
> We call the location using:
> 
> chronyd\_systemd[system\_distro]
> 
> System\_distro is something we’ve defined with the major and minor OS versions smashed together (Debian10, CentOS7, etc.)
> 
> In the vars/main.yml file we have:
> 
> chronyd\_systemd:  
> Debian10: /etc/systemd/system/chronyd.service
> 
> Debian11: /lib/systemd/system/chronyd.service
> 
> Ideally we’d like something like this:
> 
> chronyd-systemd:  
> Debian11: /lib/systemd/system/chronyd.service OR /etc/systemd/system/chronyd.service
> 
> How would we go about doing this?

This should expand to what you want (untested):

“{{ chronyd\_systemd[ansible\_distribution ~ ansible\_distribution\_major\_version] }}”

---

<div class="post-metadata">

**Author:** ![Kathy\_L](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kathy_l/32/2652_2.png) [@Kathy\_L](https://forum.ansible.com/u/Kathy_L)\
**Post date:** [May 18, 2023, 2:28pm UTC](https://forum.ansible.com/t/multiple-entries-for-a-variable/38007/3 "2023-05-18T14:28:58Z")

</div>

Actually, that is how we define system\_distro already.

I’m really interesting in how to do something like the following:

chronyd-systemd:  
Debian11: /lib/systemd/system/chronyd.service OR /etc/systemd/system/chronyd.service

In other words, for Debian 11, define two different locations to look at.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [May 18, 2023, 2:41pm UTC](https://forum.ansible.com/t/multiple-entries-for-a-variable/38007/4 "2023-05-18T14:41:14Z")

</div>

file lookups work on the controller, not the target hosts. So you’d be stuck doing a ansible.builtin.stat on those paths first, then some magic jinja expressions on the results. It gets messy, much messier than what you’re already doing.

But, unless you’re the creating a service yourself - and I mean the whole service, not just the systemd unit file - this is not the way to go. Systemd provides a mechanism for the sysadmin to override and/or add to the settings in a vendor- or distro-provided service unit. You should consider putting your overrides in /etc/systemd/system/chronyd.service.d/ and leaving the upstream service unit file(s) alone. This also preserves your mods and avoids conflicts across chronyd updates.
