molecule
molecule copied to clipboard
Shell variable expansion
Issue Type
- Bug report
Molecule and Ansible details
$ ansible --version && molecule --version
ansible 2.9.11
config file = /home/vagrant/ansible.cfg
configured module search path = ['/home/vagrant/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/vagrant/.local/lib/python3.6/site-packages/ansible
executable location = /home/vagrant/.local/bin/ansible
python version = 3.6.9 (default, Jul 17 2020, 12:50:27) [GCC 8.4.0]
molecule 3.0.6
ansible==2.9.11 python==3.6
Molecule installation method (one of):
- pip
Ansible installation method (one of):
- pip
Detail any linters or test runners used:
|
set -e
yamllint -f colored .
ansible-lint --force-color
Desired Behavior
Using shell expansion + fails inside of molecule.yml instead of correctly expanding/replacing
Trying to only include formatting characters if a variable is defined.
platforms:
- name: instance${CI_JOB_ID:+-}${CI_JOB_ID}
According to the docs this should produce an instance name of either instance or instance-<CI_JOB_ID>.
Further shell expansion information:
${parameter:+word} parameter is null or unset, nothing is substituted, otherwise the expansion of word is substituted.
Actual Behaviour
Please give some details of what is actually happening.
Include a minimum complete verifiable example with
output of running molecule --debug.
ERROR: parsing config file '/ansible/roles/ca-sso-policyserver/molecule/default/molecule.yml'.
Invalid placeholder in string: line 11, col 19
---
dependency:
name: galaxy
driver:
name: docker
lint: |
set -e
yamllint -f colored .
ansible-lint --force-color
platforms:
- name: instance${CI_JOB_ID:+-}${CI_JOB_ID}
Hello,
I believe this is due to the fact that a fallback must be provied for the value if the variable is missing
- name: instance${CI_JOB_ID:-HELLO}
Produces instanceHELLO without passing CI_JOB_ID.
When passed CI_JOB_ID=WORLD, the resulting name is correctly instanceWORLD
@zyphermonkey have you figured this out?
I think you missing the + it acts as a replacement. So if the first variable has a value then use whatever is after the +.
I don't have any issue with the more commonly use -.
It isn't a full BASH compatible setup as @fourstepper correctly suggested. Here is the PR where I implemented the BASH style expansion, the implementation is rather simple and just checks for :-
Might be worth noting in the docs :)
https://github.com/ansible-community/molecule/pull/2223
@zyphermonkey can this be closed?
@zyphermonkey can this be closed?
For sure, but I do agree the limited BASH functionality should be noted in the docs when possible or to make an update to include compatibility for :+.
I'll let you decide if you want to keep this open as a task to add :+ or close it if there are no plans to do so.