You are not logged in.

#1 2020-07-13 13:28:43

Durag
Member
Registered: 2012-08-05
Posts: 9

Run hostnamectl in Arch Linux Docker container (Ansible/Molecule)

Hi all!

At first: I hope I'm in the right sub-forum!

I want to create a role for Ansible to configure my network. I'm also trying to test my role with molecule in an Arch Linux Docker container.
Inside my role I'm using Ansible's hostname module. But when I run my molecule test I get the following error message: "Could not set property: Failed to set static hostname: Device or resource busy."

I'm new to Docker, so maybe its some missing capabilities in my configuration. Maybe something is wrong in my Dockerfile. But maybe its not possible at all to get the hostnamectl command running in an Arch Linux Docker container.
I've installed the inetutils package and ran the hostname command, which worked. But at least Ansibles hostname module doesn't care about the hostname command.

I hope you can give me some information on my questions!

Here are the files I'm using:

network/defaults/main.yml

---
network_hostname: archlinux

network/molecule/default/converge.yml

---
- name: Converge
  hosts: all
  roles:
    - network

network/molecule/default/molecule.yml

---
dependency:
  name: galaxy
driver:
  name: docker
lint: |
  set -e
  yamllint .
  ansible-lint
platforms:
  - name: instance
    image: marcstraube/docker-archlinux-base-ansible:latest
    pre_build_image: true
    privileged: true
    command: "/usr/lib/systemd/systemd"
    env:
      container: docker
    capabilities:
      - SYS_ADMIN
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    tmpfs:
      - /run
      - /run/lock
      - /tmp
provisioner:
  name: ansible
  inventory:
    host_vars:
      instance:
        ansible_user: ansible
scenario:
  name: default
  create_sequence:
    - create
  check_sequence:
    - destroy
    - create
    - converge
    - check
    - destroy
  converge_sequence:
    - create
    - converge
  destroy_sequence:
    - destroy
  test_sequence:
    - lint
    - destroy
    - syntax
    - create
    - converge
    - idempotence
    - destroy
verifier:
  name: ansible

network/tasks/main.yml

---
- name: Set hostname 
  become: true 
  hostname: 
    name: "{{ network_hostname }}"

Thanks for your help!

Last edited by Durag (2020-07-13 13:29:52)

Offline

Board footer

Powered by FluxBB