Refactor logic for running in containers 25/57525/1
authorDaniel Farrell <dfarrell@redhat.com>
Mon, 28 Mar 2016 21:39:56 +0000 (17:39 -0400)
committerDaniel Farrell <dfarrell@redhat.com>
Fri, 19 May 2017 16:52:25 +0000 (12:52 -0400)
New CentOS containers (7.2.1511 and not 7.1.1503) ship full systemd,
instead of using fakesystemd or not including it. It doesn't work
without modifying the Dockerfile and/or passing special params to the
`docker run` command, and it's generally not recommended for use in
containers, so we don't want to use it when provisioning a container.

The old checks were seeing systemd and (rightly so, it's installed) and
attempting to use it in containers. The new one directly checks if
running in a container instead of inferring from presence or absence of
systemd.

Change-Id: I9ee7c86c947396a3452a1c0b54d576bb9d512b47
Signed-off-by: Daniel Farrell <dfarrell@redhat.com>
handlers/restart_odl.yml
handlers/start_odl.yml
handlers/stop_odl.yml
tasks/in_container.yml [new file with mode: 0644]
tasks/is_systemd_installed.yml [deleted file]
tasks/open_nb_rest_port.yml
tasks/start_odl.yml

index ee198ab792a97c1e8b874286ae3a515a563b8d34..0a94c30bb70224bc4184284c24190ee420347fb6 100644 (file)
@@ -1,5 +1,5 @@
 - name: Restart ODL
-  when: systemd_installed.rc == 0
+  when: in_container.rc == 1
   service:
     name=opendaylight
     state=restarted
index 3f19dad926471ee7e951a3d0c1892f0890cc312d..7048324acce6bd19e129f65c295eacc65b2321cb 100644 (file)
@@ -1,5 +1,5 @@
 - name: Start ODL
-  when: systemd_installed.rc == 0
+  when: in_container.rc == 1
   service:
     name=opendaylight
     state=started
index 77f9bdfb1fd3ebeed94a4dfbfdb722128597d537..3826539bb4b1dc3c4f0efad81c436d915af6edb9 100644 (file)
@@ -1,5 +1,5 @@
 - name: Stop ODL
-  when: systemd_installed.rc == 0
+  when: in_container.rc == 1
   service:
     name=opendaylight
     state=stopped
diff --git a/tasks/in_container.yml b/tasks/in_container.yml
new file mode 100644 (file)
index 0000000..922637b
--- /dev/null
@@ -0,0 +1,6 @@
+---
+- name: Check if in a container
+  command: grep -q docker /proc/1/cgroup
+  failed_when: in_container.rc not in [0, 1]
+  changed_when: false
+  register: in_container
diff --git a/tasks/is_systemd_installed.yml b/tasks/is_systemd_installed.yml
deleted file mode 100644 (file)
index 8de032c..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
----
-- name: Check if systemd is installed
-  command: rpm -q systemd
-  failed_when: systemd_installed.rc not in [0, 1]
-  changed_when: false
-  register: systemd_installed
index fc6de5643a3e8e6a8de1185f92438f640d464457..1a94f9c7a4b32955a9d4352511c87bb6cd285a93 100644 (file)
@@ -1,15 +1,15 @@
 ---
-- include: is_systemd_installed.yml
+- include: in_container.yml
 
 - name: Check if FirewallD service is running
   command: systemctl is-active firewalld
   failed_when: firewalld_status.stdout not in ['unknown', 'active']
   changed_when: false
   register: firewalld_status
-  when: systemd_installed.rc == 0
+  when: in_container.rc == 1
 
 - name: Open ODL NB REST port via FirewallD
-  when: systemd_installed.rc == 0 and firewalld_status.stdout == 'active'
+  when: in_container.rc == 1 and firewalld_status.stdout == 'active'
   firewalld:
     port={{ nb_rest_port }}/tcp
     state=enabled
index bb9c4e93f55de7eea688bf741cb7e0500efa3805..404c330ffca4fd15e869504d90505d7bc5479d74 100644 (file)
@@ -1,5 +1,5 @@
 ---
-- include: is_systemd_installed.yml
+- include: in_container.yml
 
 - include: start_odl_systemd_service.yml
-  when: systemd_installed.rc == 0
+  when: in_container.rc == 1