Skip to content

community.general.lxd connection not working with molecule #4886

@antonc42

Description

@antonc42

Summary

When I try to run molecule create with the lxd driver, it creates the lxc container correctly, but then gives a warning and then fails to run a command on the container.

[WARNING]: The "ansible_collections.community.general.plugins.connection.lxd" connection plugin has an improperly configured remote target value, forcing "inventory_hostname" templated value instead of the string

After some debugging, I found that the remote_addr value was being set to the literal string 'inventory_hostname' instead of the value of the current host's inventory_hostname. I found another connection plugin that had fixed a similar issue.

Applying this patch to the plugins/connection/lxd.py file fixes the problem.

fix_lxd_inventory_hostname.patch.txt

Issue Type

Bug Report

Component Name

plugins/connection/lxd.py

Ansible Version

$ ansible --version
ansible [core 2.13.1]
  config file = /home/anton/ansible-collection-oit-ne-servers/roles/common/ansible.cfg
  configured module search path = ['/home/anton/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/anton/ansible-collection-oit-ne-servers/.venv/lib/python3.10/site-packages/ansible
  ansible collection location = /home/anton/ansible-collection-oit-ne-servers/roles/common/.collections
  executable location = /home/anton/ansible-collection-oit-ne-servers/.venv/bin/ansible
  python version = 3.10.5 (main, Jun 11 2022, 16:53:24) [GCC 9.4.0]
  jinja version = 3.1.2
  libyaml = False

Community.general Version

$ ansible-galaxy collection list community.general
Collection        Version
----------------- -------
community.general 5.2.0 

Configuration

$ ansible-config dump --only-changed

OS / Environment

cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.4 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.4 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

Steps to Reproduce

$ mkdir tmp
$ cd tmp
$ python3 -m venv .venv
$ . .venv/bin/activate
$ python3 -m pip install --upgrade pip setuptools wheel
$ python3 -m pip install ansible molecule molecule-lxd
$ molecule init role tmp.common --driver-name lxd
$ cd common

Modify molecule/default/molecule.yml:

dependency:
  name: galaxy
driver:
  name: lxd
platforms:
  - name: centos-stream-8
    source:
      type: image
      mode: pull
      server: https://images.linuxcontainers.org
      protocol: simplestreams
      alias: centos/8-Stream/amd64
    profiles: ["default"]
provisioner:
  name: ansible
verifier:
  name: ansible
$ molecule create

Expected Results

I expected that the lxd container would be properly created and prepared.

Actual Results

PLAY [Prepare] *****************************************************************

TASK [Install basic packages to bare containers] *******************************
[WARNING]: The "lxd" connection plugin has an improperly configured remote
target value, forcing "inventory_hostname" templated value instead of the
string
fatal: [centos-stream-8]: FAILED! => {"changed": true, "msg": "non-zero return code", "rc": 1, "stderr": "Error: Instance not found\n", "stderr_lines": ["Error: Instance not found"], "stdout": "", "stdout_lines": []}

Code of Conduct

  • I agree to follow the Ansible Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue/PR relates to a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions