Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Hostname module does not recognize systemd #1

Open
AlexisLessard opened this issue Jun 5, 2019 · 4 comments
Open

Hostname module does not recognize systemd #1

AlexisLessard opened this issue Jun 5, 2019 · 4 comments

Comments

@AlexisLessard
Copy link

Summary
Using the ansible module Hostname on a docker container using molecule, the following message appears:

fatal: [Fedora]: FAILED! => {"changed": false, "msg": "Command failed rc=1, out=, err=System has not been booted with systemd as init system (PID 1). Can't operate.\nFailed to create bus connection: Host is down\n"}  

However, the task completes without any problems on Ubuntu 16.04 and 18.04.

Ansible version

ansible 2.7.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/alles60/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/alles60/misc/config-linux-molecule/lib/python3.7/site-packages/ansible
  executable location = /home/alles60/misc/config-linux-molecule/bin/ansible
  python version = 3.7.3 (default, May 11 2019, 00:45:16) [GCC 8.3.1 20190223 (Red Hat 8.3.1-2)]

Configuration
excerp from molecule.yml:

platforms:
  - name: Fedora
    image: geerlingguy/docker-fedora29-ansible
    pre_build_image: true
    privileged: true
  - name: Ubuntu-16.04
    image: geerlingguy/docker-ubuntu1604-ansible
    pre_build_image: true
    privileged: true
  - name: Ubuntu-18.04
    image: geerlingguy/docker-ubuntu1804-ansible
    pre_build_image: true
    privileged: true

Steps to reproduce
Run the following task on a vanilla container with the image docker-fedora29-ansible:

- name: Change the hostname
  become: yes
  hostname:
    name: "{{ config_hostname }}
@AlexisLessard
Copy link
Author

AlexisLessard commented Jun 9, 2019

The hostname ansible module uses a systemd strategy for Fedora, but uses a more custom one for Debian based modules (On a side note, My god, is the ansible source code beautiful or what? So easy to understand). Running bash inside the container, I receive the following output:

[root@Fedora /]# hostnamectl --transient set-hostname test
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to create bus connection: Host is down

Similar messages appear for other systemd commands. For instance, systemctl status gives the same message.
I'm gonna try to find what is causing this message, and how the image could be adapted to fix this.

@AlexisLessard
Copy link
Author

Running the container with the following command (wich is shown in the README file), I get this:

docker run --detach --privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro geerlingguy/docker-fedora29-ansible:latest
docker exec -it hardcore_cori /bin/bash                                                          
[root@49212a090e69 /]# systemctl status
● 49212a090e69
    State: running
     Jobs: 0 queued
   Failed: 0 units
    Since: Sun 2019-06-09 22:28:53 UTC; 23s ago
   CGroup: /system.slice/containerd.service
           ├─init.scope
           │ └─1 /usr/sbin/init
           └─system.slice
             └─systemd-journald.service
               └─15 /usr/lib/systemd/systemd-journald

There was an issue with unmounted volumes. I will implement it inside molecule.

@AlexisLessard
Copy link
Author

AlexisLessard commented Jun 10, 2019

Visibly, the image wasn't starting using systemd with Molecule. I've modified my platform configuration like so:

  - name: Fedora
    image: geerlingguy/docker-fedora29-ansible
    pre_build_image: True
    privileged: True
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    command: /usr/sbin/init

Now the error message reads like so:

[root@Fedora /]# hostnamectl --transient set-hostname test
Failed to create bus connection: No such file or directory

Same thing happens on a vanilla image that I run on the command line. Time to find a more specific way to solve this. But I'm getting there, as simple commandes like systemctl status works.

@AlexisLessard
Copy link
Author

Excerpt from the molecule documentation for the docker driver:

If specifying the CMD directive in your Dockerfile.j2 or consuming a built image which declares a CMD directive, then you must set override_command: False. Otherwise, Molecule takes care to honour the value of the command key or uses the default of bash -c "while true; do sleep 10000; done" to run the container until it is provisioned.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant