ansible ... molecule.yml - how to refer to env variables define in same file?

I cam trying to restructure a molecule file to use a common playbook to reduce code duplication.

I can get it to work with a relative path but using referring to the other playbook relative to env var like ANSIBLE_ROLES_PATH would be more intuitive.

The commented out versions below don't work but the third variant is fine.

Is there a way to do this?

more molecule.yml
 // SNIP 
provisioner:
  name: ansible
  config_options:
    defaults:
      callback_whitelist: "profile_tasks, timer"
  env:
    ANSIBLE_ROLES_PATH: ../../../../../../roles
  playbooks:
#    destroy: "{{ lookup('env', 'ANSIBLE_ROLES_PATH') }}/molecule/destroy.yml"
#    destroy: "{{ANSIBLE_ROLES_PATH}}/molecule/destroy.yml"
    destroy: "../../../../../../roles/molecule/destroy.yml"
scenario:
  name: default
verifier:
  name: testinfra
  lint:
    name: flake8

Answers

You should be able to use ${YOU_ENV_VAR} like in bash or with default value in case the variable is not set: ${YOU_ENV_VAR:-defaultvalue}

more molecule.yml
 // SNIP 
provisioner:
  name: ansible
  config_options:
    defaults:
      callback_whitelist: "profile_tasks, timer"
  env:
    ANSIBLE_ROLES_PATH: ../../../../../../roles
  playbooks:
    destroy: ${MYPLAYBOOKS_PATH:-"${ANSIBLE_ROLES_PATH}/molecule/destroy.yml"}

scenario:
  name: default
verifier:
  name: testinfra
  lint:
    name: flake8

Posted on by Anonymous

Relevant tags