geerlingguy / docker-ubuntu2204-ansible

Ubuntu 22.04 LTS (Jammy Jellyfish) Docker container for Ansible playbook and role testing.
https://hub.docker.com/r/geerlingguy/docker-ubuntu2204-ansible
MIT License
69 stars 17 forks source link

Molecule doesn't start systemd #9

Closed artis3n closed 1 year ago

artis3n commented 1 year ago

It has been some time, and this is close to #6 , but given I am not receiving that error I opted for a new issue. I cannot get Molecule working with cgroupsv2 and this container (or most others since the cgroup change, admittedly). This container works fine when executed directly, mirroring the commands in the README, but fails under Molecule during any execution of a systemd task with:

fatal: [instance]: FAILED! => {"changed": false, "msg": "failure 1 during daemon-reload: System has not been booted with systemd as init system (PID 1). Can't operate.\nFailed to connect to bus: Host is down\n"}

This occurs locally on OSX and on an ubuntu 22.04 GitHub Actions runner.

My molecule.yml is:

---
dependency:
  name: galaxy
driver:
  name: docker
platforms:
  - name: instance
    image: geerlingguy/docker-ubuntu2204-ansible:latest
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:rw
    cgroupns_mode: host
    privileged: true
    pre_build_image: true
provisioner:
  name: ansible
verifier:
  name: ansible
scenario:
  name: default
  test_sequence:
#    - dependency
    - destroy
    - syntax
    - create
    - prepare
    - converge
    - idempotence
#    - verify
#    - cleanup
    - destroy

A minimally reproducible converge.yml is:

---
- name: Converge
  hosts: all
  tasks:
    - name: ":("
      become: true
      ansible.builtin.systemd:
        daemon_reload: true

Running molecule test will result in the above error both locally and on the Ubuntu 22.04 runner.

Given the molecule PR introducing cgroupns_mode is merged and I don't see issues about this from others in the molecule and molecule-plugins repos, I am assuming I'm missing something dumb in the molecule.yml. Any thoughts as to what I should be doing to resolve this error?

dbrennand commented 1 year ago

Hey @artis3n

I managed to fix this by including command: /usr/sbin/init in my molecule.yml:

---
dependency:
  name: galaxy
driver:
  name: podman
platforms:
  - name: instance
    image: docker.io/geerlingguy/docker-ubuntu2204-ansible:latest
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:rw
    cgroupns_mode: host
    command: /usr/sbin/init
    privileged: true
    pre_build_image: true
provisioner:
  name: ansible
(sandbox) ➜  sandbox molecule login  
INFO     Running default > login
root@instance:/# systemctl status
● instance
    State: degraded

PLAY [Converge] ****************************************************************

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

TASK [:(] **********************************************************************
ok: [instance]

PLAY RECAP *********************************************************************
instance                   : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Hope this helps 😄 👍🏻

artis3n commented 1 year ago

Of course! Thanks. Since this post I broke out what images now use /usr/sbin/init vs. other commands. I will close it. There are a few distros I continue to have issue with, but :shrug: I'll leave them on an ubuntu-20.04 runner. https://github.com/artis3n/ansible-role-tailscale/blob/e217453d8c04c4a0ff1d2528c240f76d135a91d1/.github/workflows/pull_request_target.yml#L57

trallnag commented 3 months ago

Helped me as well, thanks

platforms:
  - name: ubuntu-2404
    image: docker.io/geerlingguy/docker-ubuntu2404-ansible
    command: /usr/sbin/init
    pre_build_image: true
    cgroupns_mode: host
    privileged: true
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:rw
      - /var/lib/containerd