multiple entries for a variable

24 views
Skip to first unread message

Kathy L

unread,
May 18, 2023, 9:39:33 AM5/18/23
to Ansible Project
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?

Dick Visser

unread,
May 18, 2023, 9:56:02 AM5/18/23
to ansible...@googlegroups.com
This should expand to what you want (untested):


"{{ chronyd_systemd[ansible_distribution ~ ansible_distribution_major_version] }}"




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2e58e6a6-e38b-4a6a-91c6-6f631155c6fan%40googlegroups.com.
--
Sent from Gmail Mobile

Kathy L

unread,
May 18, 2023, 10:28:58 AM5/18/23
to Ansible Project
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.

Todd Lewis

unread,
May 18, 2023, 10:41:27 AM5/18/23
to ansible...@googlegroups.com, uto...@gmail.com
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.
--
Todd
Reply all
Reply to author
Forward
0 new messages