ansible / ansible

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy and maintain. Automate everything from code deployment to network configuration to cloud management, in a language that approaches plain English, using SSH, with no agents to install on remote systems. https://docs.ansible.com.
https://www.ansible.com/
GNU General Public License v3.0
62.73k stars 23.87k forks source link

Systemd module behavior differs from systemd when enabling services #46744

Open tadeboro opened 6 years ago

tadeboro commented 6 years ago
SUMMARY

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

ISSUE TYPE
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:

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.

ansibot commented 6 years ago

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 commented 5 years ago

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

tadeboro commented 5 years ago

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.

mkrizek commented 5 years ago

I can reproduce this issue.

ohenley commented 4 years ago

+1

ansibot commented 4 years ago

Files identified in the description:

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

click here for bot help

kuznero commented 3 years ago

Can confirm the same issue in ansible 2.10.4

drawks commented 3 months ago

Is this something which is being worked on?