Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify the ansible collection path #3999

Open
cidrblock opened this issue Aug 11, 2023 · 3 comments
Open

Clarify the ansible collection path #3999

cidrblock opened this issue Aug 11, 2023 · 3 comments
Assignees
Milestone

Comments

@cidrblock
Copy link
Contributor

cidrblock commented Aug 11, 2023

In the getting started guide it is recommended to create an ansible.cfg file in the extension directory. I don't believe this is ever used.

A new ansible.cfg file is built in each ephemeral directory and used for each step.

I think the best approach here is to suggest the following entry in each scenario/molecule.yml file:

provisioner:
  name: ansible
  config_options:
    defaults:
      collections_path: ${ANSIBLE_COLLECTIONS_PATH}

and then have the user set the ANSIBLE_COLLECTIONS_PATH environment variable at the command line prior to running molecule

export ANSIBLE_COLLECTIONS_PATH=/home/user/working/collections

We might also consider adding this to the molecule.yml file that is templated out during init.

This leaves a hard coded path out of the code, but does require the next user to set the var after cloning.
(Note: The tox-ansible plugin sets this environment variable for the user, so if the molecule scenarios are being run with pytest or tox this should be taken care of. This can be seen here using all three in a collection here ansible.scm

Feedback welcome.

Brad

@cidrblock cidrblock added this to the Molecule 6 milestone Aug 12, 2023
@cidrblock
Copy link
Contributor Author

@ajinkyau Can you look into this? ping me if more info is needed

@audgirka
Copy link
Contributor

audgirka commented Dec 8, 2023

@cidrblock I'm in favour of adding the provisioner entry to the molecule.yml file during initialisation.

@r0x0d
Copy link

r0x0d commented Dec 8, 2023

Hi, @cidrblock and @ajinkyau! I have tried the approach @cidrblock mentioned in the comment, but it didn't work out for me.

I can see that molecule was able to identify and correctly populate both the ansible.cfg and molecule.yml in the ephemeral directory, but when I run molecule converge, it still thinks that it should have the collection's path alongside the extension's folder.

image

My ansible.cfg generated inside ~/.cache/molecule/extensions/default:

# Molecule managed

[defaults]
ansible_managed = Ansible managed: Do NOT edit this file manually!
display_failed_stderr = True
forks = 50
retry_files_enabled = False
host_key_checking = False
nocows = 1
interpreter_python = auto_silent
collections_path = /home/r0x0d/Workspace/infra/
[ssh_connection]
scp_if_ssh = True
control_path = %(directory)s/%%h-%%p-%%r

and my molecule.yml, also generated inside ~/.cache/molecule/extensions/default:

# Molecule managed

---
dependency:
  command: null
  enabled: true
  env: {}
  name: galaxy
  options: {}
driver:
  name: vagrant
  options:
    managed: true
  provider:
    name: libvirt
  safe_files: []
  ssh_connection_options: []
platforms:
  - box: eurolinux-vagrant/centos-7
    cpus: 2
    default_box: eurolinux-vagrant/centos-7
    hostname: infra.convert2rhel
    memory: 2048
    name: instance
prerun: true
provisioner:
  ansible_args: []
  children: {}
  config_options:
    defaults:
      collections_path: /home/r0x0d/Workspace/infra/
  connection_options: {}
  env: {}
  inventory:
    group_vars: {}
    host_vars: {}
    hosts: {}
    links: {}
  log: true
  name: ansible
  options: {}
  playbooks:
    cleanup: cleanup.yml
    converge: converge.yml
    create: create.yml
    destroy: destroy.yml
    prepare: prepare.yml
    side_effect: side_effect.yml
    verify: verify.yml
role_name_check: 0
scenario:
  check_sequence:
    - dependency
    - cleanup
    - destroy
    - create
    - prepare
    - converge
    - check
    - cleanup
    - destroy
  cleanup_sequence:
    - cleanup
  converge_sequence:
    - dependency
    - create
    - prepare
    - converge
  create_sequence:
    - dependency
    - create
    - prepare
  destroy_sequence:
    - dependency
    - cleanup
    - destroy
  name: default
  test_sequence:
    - dependency
    - cleanup
    - destroy
    - syntax
    - create
    - prepare
    - converge
    - idempotence
    - side_effect
    - verify
    - cleanup
    - destroy
verifier:
  additional_files_or_dirs: []
  enabled: true
  env: {}
  name: ansible
  options: {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Roadmap
Development

No branches or pull requests

3 participants