New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Systemd module behavior differs from systemd when enabling services #46744

Open
tadeboro opened this Issue Oct 10, 2018 · 4 comments

Comments

Projects
None yet
6 participants
@tadeboro
Copy link

tadeboro commented Oct 10, 2018

SUMMARY

Actions that systemd module takes when enabling/disabling a service differ from the actions that calling systemctl from console produces.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

systemd

ANSIBLE VERSION
ansible 2.8.0.dev0 (systemd-unit-enabled-fix c9c8653e1a) last updated 2018/10/10 12:34:32 (GMT +200)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/tadej/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/tadej/xlab/ansible/ansible/lib/ansible
  executable location = /home/tadej/xlab/ansible/ansible/bin/ansible
  python version = 2.7.15 (default, Sep 21 2018, 23:26:48) [GCC 8.1.1 20180712 (Red Hat 8.1.1-5)]
CONFIGURATION
OS / ENVIRONMENT

Ansible versions tested:

  • 2.8.0.dev0 from git on GNU/Linux Fedora 28
  • 2.7 from pypi on GNU/Linux Fedora 28
  • 2.6 from official repos on GNU/Linux Fedora 28

Hosts being managed were Fedora 28 and CentOS 7.

STEPS TO REPRODUCE

Run the following playbook (we assume here that tftp-server package was installed on Fedora/CentOS):

- hosts: all
  become: yes

  tasks:
    - name: start tftp server
      service:
        name: tftp
        enabled: yes

Relevant systemd units: tftp.service and tftp.socket

[Unit]
Description=Tftp Server
Requires=tftp.socket
Documentation=man:in.tftpd

[Service]
ExecStart=/usr/sbin/in.tftpd -s /var/lib/tftpboot
StandardInput=socket

[Install]
Also=tftp.socket
[Unit]
Description=Tftp Server Activation Socket

[Socket]
ListenDatagram=69

[Install]
WantedBy=sockets.target
EXPECTED RESULTS

tftp.socket service should be enabled, since this is what Install section of the tftp.service dictates.

ACTUAL RESULTS

tftp.socket is not modified at all.

@tadeboro tadeboro referenced a pull request that will close this issue Oct 10, 2018

Open

Rework the systemd service state detection #46747

@ansibot

This comment has been minimized.

Copy link
Contributor

ansibot commented Oct 10, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@jorijinnall

This comment has been minimized.

Copy link
Contributor

jorijinnall commented Nov 9, 2018

Can you detail how you check "tftp.socket is not modified at all." ?

@tadeboro

This comment has been minimized.

Copy link
Author

tadeboro commented Nov 9, 2018

When tftp-related services are disabled and stopped, systemctl has this to say about the system:

$ systemctl status tftp
● tftp.service - Tftp Server
   Loaded: loaded (/usr/lib/systemd/system/tftp.service; indirect; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:in.tftpd
$ systemctl status tftp.socket
● tftp.socket - Tftp Server Activation Socket
   Loaded: loaded (/usr/lib/systemd/system/tftp.socket; disabled; vendor preset: disabled)
   Active: inactive (dead)
   Listen: [::]:69 (Datagram)

Running the sample playbook against this host outputs:

$ ansible-playbook -i inventory x.yml 

PLAY [all] ***********************************************************

TASK [Gathering Facts] ***********************************************
ok: [172.16.93.126]

TASK [start tftp server] *********************************************
ok: [172.16.93.126]

PLAY RECAP ***********************************************************
172.16.93.126        : ok=2    changed=0    unreachable=0    failed=0

Ansible reported no change, which is not right, since it should enable tftp.socket. If I query systemd for service statuses again, I get back the same statuses as before, confirming that ansible skipped the enable part:

$ systemctl status tftp
● tftp.service - Tftp Server
   Loaded: loaded (/usr/lib/systemd/system/tftp.service; indirect; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:in.tftpd
$ systemctl status tftp.socket
● tftp.socket - Tftp Server Activation Socket
   Loaded: loaded (/usr/lib/systemd/system/tftp.socket; disabled; vendor preset: disabled)
   Active: inactive (dead)
   Listen: [::]:69 (Datagram)

Enabling tftp service using systemd reports this:

# systemctl enable tftp
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket → /usr/lib/systemd/system/tftp.socket.

And this is the status output after that command:

$ systemctl status tftp
● tftp.service - Tftp Server
   Loaded: loaded (/usr/lib/systemd/system/tftp.service; indirect; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:in.tftpd
$ systemctl status tftp.socket
● tftp.socket - Tftp Server Activation Socket
   Loaded: loaded (/usr/lib/systemd/system/tftp.socket; enabled; vendor preset: disabled)
   Active: inactive (dead)
   Listen: [::]:69 (Datagram)

As can be seen from the output, enabling tftp.service automatically enabled tftp.socket as instructed by the service file.

Ansible fails to perform this because it interprets the indirect state of the tftp.service as enabled and skips the enable part of the task.

I noticed this bug when tftp server stopped responding after the reboot.

@webknjaz webknjaz changed the title Sytemd module behavior differs from systemd when enabling services Systemd module behavior differs from systemd when enabling services Dec 11, 2018

@mkrizek

This comment has been minimized.

Copy link
Contributor

mkrizek commented Dec 11, 2018

I can reproduce this issue.

@mkrizek mkrizek added the verified label Dec 11, 2018

webknjaz added a commit to webknjaz/ansible that referenced this issue Jan 18, 2019

webknjaz added a commit to webknjaz/ansible that referenced this issue Feb 15, 2019

@ansibot ansibot added the system label Feb 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment