molecule-plugins
molecule-plugins copied to clipboard
vagrant - Could not resolve hostname instance
Hello
I'm trying to get molecule working with vagrant.
I've tried various examples, such as the following:
---
driver:
name: vagrant
provider:
# Can be any supported provider (virtualbox, parallels, libvirt, etc)
# Defaults to virtualbox
name: libvirt
# Run vagrant up with --provision.
# Defaults to --no-provision)
provision: no
# vagrant-cachier configuration
# Defaults to 'machine'
# Any value different from 'machine' or 'box' will disable it
cachier: machine
# If set to false, set VAGRANT_NO_PARALLEL to '1'
# Defaults to true
parallel: true
# vagrant box to use by default
# Defaults to 'generic/alpine316'
default_box: 'bento/ubuntu-22.04'
platforms:
- name: instance
# If specified, set host name to hostname, unless it's set to False and
# the host name won't be set. In all other cases (including default) use
# 'name' as host name.
hostname: foo.bar.com
# List of dictionaries mapped to `config.vm.network`
interfaces:
- auto_config: true
network_name: private_network
type: static
ip: 192.168.10.42
# List of raw Vagrant `config` options
instance_raw_config_args:
# use single quotes to avoid YAML parsing as dict due to ':'
- 'vm.synced_folder ".", "/vagrant", type: "rsync"'
# Run 'uname' a provisionning step **needs 'provision: true' to work**
- 'vm.provision :shell, inline: "uname"'
# Dictionary of `config` options. Note that string values need to be
# explicitly enclosed in quotes.
config_options:
ssh.keep_alive: yes
ssh.remote_user: 'vagrant'
synced_folder: true
box: bento/ubuntu-22.04
# box_version: 32.20200422.0
box_url:
memory: 512
cpus: 1
# Dictionary of options passed to the provider
provider_options:
video_type: 'vga'
# List of raw provider options
provider_raw_config_args:
- cpuset = '1-4,^3,6'
But I always get the following error:
TASK [Gather system info] ******************************************************
fatal: [instance]: UNREACHABLE! =>
{
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname instance: Name or service not known",
"unreachable": true
}
Versions
molecule 25.2.0 using python 3.11 ansible:2.18.2 podman:23.7.0 from molecule_plugins requiring collections: containers.podman>=1.7.0 ansible.posix>=1.3.0 openstack:23.7.0 from molecule_plugins requiring collections: openstack.cloud>=2.1.0 ec2:23.7.0 from molecule_plugins docker:23.7.0 from molecule_plugins requiring collections: community.docker>=3.10.2 ansible.posix>=1.4.0 containers:23.7.0 from molecule_plugins requiring collections: ansible.posix>=1.3.0 community.docker>=1.9.1 containers.podman>=1.8.1 gce:23.7.0 from molecule_plugins requiring collections: google.cloud>=1.0.2 community.crypto>=1.8.0 vagrant:23.7.0 from molecule_plugins azure:23.7.0 from molecule_plugins default:25.2.0 from molecule
Ran into the same issue, just made it work.
For some reasons molecule init copies default playbooks for create, destroy, converge. Replace the files in your scenario with corresponding ones from src/molecule_plugins/vagrant/playbooks in this repo.
Also make sure you have all the necessary deps in your requirements.txt, pip install 'molecule-plugins[vagrant]' do not seem to work. These are the following:
pyyaml >= 5.1
python-vagrant == 1.0.0
selinux
Hope this helps!
Thanks, this does help.
I'm now getting the following errors:
ERROR! couldn't resolve module/action 'vagrant'. This often indicates a misspelling, missing collection, or incorrect module path.
The error appears to be in '/home/ubuntu/my-project/collections/ansible_collections/org/bigcat/extensions/molecule/kvm/destroy.yml': line 8, column 9, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- name: Destroy molecule instance(s)
^ here
CRITICAL Ansible return code was 4, command was: ansible-playbook --inventory /home/ubuntu/my-project/collections/ansible_collections/.venv/.ansible/tmp/molecule.IO93.kvm/inventory --skip-tags molecule-notest,notest /home/ubuntu/my-project/collections/ansible_collections/org/bigcat/extensions/molecule/kvm/destroy.yml
WARNING An error occurred during the test sequence action: 'destroy'. Cleaning up.
INFO Running kvm > cleanup
WARNING Skipping, cleanup playbook not configured.
INFO Running kvm > destroy
ERROR! couldn't resolve module/action 'vagrant'. This often indicates a misspelling, missing collection, or incorrect module path.
The error appears to be in '/home/ubuntu/my-project/collections/ansible_collections/org/bigcat/extensions/molecule/kvm/destroy.yml': line 8, column 9, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- name: Destroy molecule instance(s)
^ here
Also make sure you have all the necessary deps in your
requirements.txt
Can you be more explicit on what I should have?
If I dont have molecule-plugins installed I get CRITICAL Failed to find driver vagrant. Please ensure that the driver is correctly installed.
And, regardless of using 'molecule-plugins[vagrant]' and or python-vagrant I get the same error:
The error appears to be in '/home/ubuntu/my-project/collections/ansible_collections/org/bigcat/extensions/molecule/kvm/destroy.yml': line 8, column 9, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- name: Destroy molecule instance(s)
^ here
Clearly this is a problem with dependencies. But I cant figure out, or find any docs on, what exact dependencies I need.
pip install 'molecule-plugins[vagrant]'do not seem to work.
In what way?
$ python3 -m pip install --force-reinstall molecule-plugins[vagrant]
[...]
Successfully installed Jinja2-3.1.5 MarkupSafe-3.0.2 PyYAML-6.0.2 ansible-compat-25.1.1 ansible-core-2.18.2 attrs-25.1.0 bracex-2.5.post1 cffi-1.17.1 click-8.1.8 click-help-colors-0.9.4 cryptography-44.0.0 enrich-1.2.7 jsonschema-4.23.0 jsonschema-specifications-2024.10.1 markdown-it-py-3.0.0 mdurl-0.1.2 molecule-25.2.0 molecule-plugins-23.7.0 packaging-24.2 pluggy-1.5.0 pycparser-2.22 pygments-2.19.1 python-vagrant-1.0.0 referencing-0.36.2 resolvelib-1.0.1 rich-13.9.4 rpds-py-0.22.3 subprocess-tee-0.4.2 typing-extensions-4.12.2 wcmatch-10.0
My requirements.txt: https://github.com/konstruktoid/ansible-role-hardening/blob/master/requirements-dev.txt
and default Molecule: https://github.com/konstruktoid/ansible-role-hardening/blob/master/molecule/default/molecule.yml