Molecule failes when use ansible vault.
linuxpld opened this issue · 1 comments
linuxpld commented
Issue Type
- Bug report
Molecule and Ansible details
ansible --version && molecule --version
ansible [core 2.12.4]
config file = None
configured module search path = ['/Users/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/user/Git/python-ansible/lib/python3.9/site-packages/ansible
ansible collection location = /Users/user/.ansible/collections:/usr/share/ansible/collections
executable location = /Users/user/Git/python-ansible/bin/ansible
python version = 3.9.12 (main, Mar 30 2022, 14:33:51) [Clang 13.1.6 (clang-1316.0.21.2)]
jinja version = 3.0.3
libyaml = True
molecule 3.5.1 using python 3.9
ansible:2.12.4
delegated:3.5.1 from molecule
docker:1.1.0 from molecule_docker requiring collections: community.docker>=1.9.1
vagrant:1.0.0 from molecule_vagrant
Molecule installation method (one of):
- pip
Ansible installation method (one of):
- pip
Detail any linters or test runners used:
In molecule.yml
file, I have.
lint: |
set -e
yamllint .
ansible-lint .
It behaves the same if no linter
Desired Behavior
According to this closed issue #1286 , I should be able to define variables in the molecule.yml and give the path to the vault file it should work but It seems it doesn't work.
Actual Behaviour
In molecule.yml
file, I have
provisioner:
name: ansible
config_options:
defaults:
vault_password_file: "~/.ansible/vault/vault.pw"
inventory:
group_vars:
password:
device_key: !vault |
$ANSIBLE_VAULT;1.1;AES256
38343932366663626637313537663530343735363335303131306661393037383731646133393866
6361353536623536653966376361373732353933613934610a353532356530633032636361386165
62353464366462653039326565393335393236663233623833306266373566363738373035306439
6633323637313037340a653963636633373433653930666532663636643563343566336262636532
6637
Molecule fails to execute with the following error:
molecule --debug test
Traceback (most recent call last):
File "/Users/user/Git/python-ansible/bin/molecule", line 8, in <module>
sys.exit(main())
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
return self.main(*args, **kwargs)
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/click/core.py", line 1053, in main
rv = self.invoke(ctx)
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/click/core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/molecule/command/test.py", line 159, in test
base.execute_cmdline_scenarios(scenario_name, args, command_args, ansible_args)
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/molecule/command/base.py", line 97, in execute_cmdline_scenarios
get_configs(args, command_args, ansible_args, glob_str), scenario_name
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/molecule/command/base.py", line 184, in get_configs
configs = [
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/molecule/command/base.py", line 185, in <listcomp>
config.Config(
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/molecule/config.py", line 63, in __call__
obj = type.__call__(cls, *args, **kwargs)
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/molecule/config.py", line 105, in __init__
self.config = self._get_config()
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/molecule/config.py", line 258, in _get_config
return self._combine(keep_string=MOLECULE_KEEP_STRING)
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/molecule/config.py", line 302, in _combine
self._preflight(s)
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/molecule/config.py", line 418, in _preflight
errors, data = schema_v3.pre_validate(data, env, MOLECULE_KEEP_STRING)
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/molecule/model/schema_v3.py", line 372, in pre_validate
data = util.safe_load(stream)
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/molecule/util.py", line 245, in safe_load
return yaml.safe_load(string) or {}
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/yaml/__init__.py", line 162, in safe_load
return load(stream, SafeLoader)
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/yaml/__init__.py", line 114, in load
return loader.get_single_data()
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/yaml/constructor.py", line 51, in get_single_data
return self.construct_document(node)
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/yaml/constructor.py", line 60, in construct_document
for dummy in generator:
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/yaml/constructor.py", line 413, in construct_yaml_map
value = self.construct_mapping(node)
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/yaml/constructor.py", line 218, in construct_mapping
return super().construct_mapping(node, deep=deep)
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/yaml/constructor.py", line 143, in construct_mapping
value = self.construct_object(value_node, deep=deep)
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/yaml/constructor.py", line 100, in construct_object
data = constructor(self, node)
File "/Users/user/Git/python-ansible/lib/python3.9/site-packages/yaml/constructor.py", line 427, in construct_undefined
raise ConstructorError(None, None,
yaml.constructor.ConstructorError: could not determine a constructor for the tag '!vault'
in "<unicode string>", line 34, column 21:
device_key: !vault |
^
ssbarnea commented
That was never supported by molecule, you cannot use !vault
constructs in molecule.yml
file, but you can use them in ansible playbooks.