How do I unmask a service in Ansible?

Viewed 2063

I'm running ansible 2.6.2 on my Mac, against a Debian-based Linux system.

There is a service called hostapd, which, when you install from the repos, comes pre-masked.

My Ansible playbook installs hostapd, configures it, and needs to unmask, start, and enable it.

In theory, it should just be as simple as:

- name: HostAPD | Make sure the service is unmasked, started, and enabled
  systemd:
    name: hostapd
    state: started
    enabled: yes
    masked: no

When I run that, I just get a:

FAILED! => {"changed": false, "msg": "Error loading unit file 'hostapd': org.freedesktop.systemd1.UnitMasked \"Unit hostapd.service is masked.\""}

I tried to separate out the tasks, and just run:

- name: HostAPD | Make sure the service is unmasked
  systemd:
    name: hostapd
    masked: no

But I still get the same error. For some reason, it's failing to unmask the service because the service is masked... I would have thought that would be a requirement - not a reason to fail.

Am I doing something wrong? I tried adding daemon_reload: yes to it as well, but that didn't help.

1 Answers

It was a bug in systemd module in Ansible 2.6 and fixed in Ansible 2.7. If possible then upgrade ansible to 2.7 or latest then retry. Otherwise, can use command or shell module as @larsks suggested.

Related