Skip to content

Commit d9393b1

Browse files
author
David Castellanos
committed
Fix systemd test for Ubuntu Xenial
The role checks if the system is running or not systemd. It checks the name of the process with PID1, and if it contains the string "systemd" assumes that the host is systemd-based. Unfortunately that check fails in Ubuntu Xenial: vagrant@mongo-xenial:~$ cat /proc/1/cmdline /sbin/init A better approach may be to check if /sbin/init is a symlink or a binary. In systemd-based systems (e.g. Ubuntu Xenial), /sbin/init is a symlink to the systemd binary: vagrant@mongo-xenial:~$ file /sbin/init /sbin/init: symbolic link to /lib/systemd/systemd In Ubuntu Trusty /sbin/init is a binary: vagrant@mongo-trusty:~$ file /sbin/init /sbin/init: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=7a4c688d009fc1f06ffc692f5f42ab09e68582b2, strippe This commit attempts to solve the problem described above. The systemd check has been rewritten to check if /sbin/init is a binary or a symlink.
1 parent d10f291 commit d9393b1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tasks/install.deb.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
- include_vars: "{{ansible_distribution}}.yml"
44

55
- name: Check if running on systemd
6-
command: cat /proc/1/cmdline
7-
register: systemd
6+
stat: path=/sbin/init
7+
register: sbin_init
88
changed_when: false
99
always_run: yes # side-effect free, so it can be run in check-mode as well
1010

1111
- name: Add systemd configuration if present
1212
copy: src=mongodb.service dest=/lib/systemd/system/mongodb.service owner=root group=root mode=0640
13-
when: "'systemd' in systemd.stdout"
13+
when: sbin_init.stat.islnk is defined and sbin_init.stat.islnk
1414

1515
- name: Add symlink for systemd
1616
file: src=/lib/systemd/system/mongodb.service dest=/etc/systemd/system/multi-user.target.wants/mongodb.service state=link
17-
when: "'systemd' in systemd.stdout"
17+
when: sbin_init.stat.islnk is defined and sbin_init.stat.islnk
1818
notify: reload systemd
1919

2020
- meta: flush_handlers
21-
when: "'systemd' in systemd.stdout"
21+
when: sbin_init.stat.islnk is defined and sbin_init.stat.islnk
2222

2323
- name: Add APT key
2424
apt_key:
@@ -48,7 +48,7 @@
4848
- name: reload systemd
4949
shell: systemctl daemon-reload
5050
changed_when: false
51-
when: "'systemd' in systemd.stdout"
51+
when: sbin_init.stat.islnk is defined and sbin_init.stat.islnk
5252

5353
- name: Install PyMongo package
5454
apt: pkg=python-pymongo state=latest

0 commit comments

Comments
 (0)