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

Molecule doesn't destroy EC2 instance if ansible_password is not provided #251

Open
milandangol opened this issue Apr 15, 2024 · 0 comments

Comments

@milandangol
Copy link

Description

When using Molecule to test my windows playbook in EC2 instances , I've noticed that the EC2 instance is not being destroyed if the ansible_password variable is not provided. This behavior is unexpected, as I would expect Molecule to clean up the resources if there is any issue.

NOTE: I am new to molecule. So i don't know if this is an issue or we can control it from somewhere

Steps to Reproduce:

  1. Create a Molecule scenario for AWS EC2 instance provisioning using Ansible.
  2. Do not provide the ansible_password variable in the scenario configuration.
  3. Run molecule create.

Expected Behavior:

The EC2 instance should be destroyed successfully, if the any issue is encounterd.

Actual Behavior:

The EC2 instance is not destroyed, and below error is raised.

Logs:

WARNING  Driver ec2 does not provide a schema.
INFO     windows scenario test matrix: dependency, syntax, create, prepare, converge, idempotence, side_effect, verify, cleanup, destroy
INFO     Performing prerun with role_name_check=0...
INFO     Running windows > dependency
Molecule windows > dependency
INFO     Running windows > syntax
Molecule windows > syntax
INFO     Running windows > create
Molecule windows > create
INFO     Found credentials in environment variables.
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.10.14/x64/bin/molecule", line 8, in <module>
    sys.exit(main())
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/command/test.py", line 113, in test
    base.execute_cmdline_scenarios(scenario_name, args, command_args, ansible_args)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/command/base.py", line 1[24](https://github.com/adexltd/ansible-role-template/actions/runs/8686195215/job/23817256609#step:8:25), in execute_cmdline_scenarios
    execute_scenario(scenario)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/command/base.py", line 167, in execute_scenario
    execute_subcommand(scenario.config, action)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/command/base.py", line 157, in execute_subcommand
    return command(config).execute(args)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/command/base.py", line 57, in __init__
    self._setup()
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/command/base.py", line 76, in _setup
    self._config.provisioner.manage_inventory()
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/provisioner/ansible.py", line 833, in manage_inventory
    self._write_inventory()
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/provisioner/ansible.py", line 879, in _write_inventory
    self._verify_inventory()
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/provisioner/ansible.py", line 933, in _verify_inventory
    if not self.inventory:
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/provisioner/ansible.py", line 650, in inventory
    connection_options = self.connection_options(instance_name)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule/provisioner/ansible.py", line 714, in connection_options
    d = self._config.driver.ansible_connection_options(instance_name)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule_ec2/driver.py", line 246, in ansible_connection_options
    conn_opts["ansible_password"] = self._get_windows_instance_pass(
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/molecule_ec2/driver.py", line [27](https://github.com/adexltd/ansible-role-template/actions/runs/8686195215/job/23817256609#step:8:28)5, in _get_windows_instance_pass
    key = load_pem_private_key(f.read(), None, default_backend())
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 494, in _handle_key_loading_error
    raise ValueError(
ValueError: ('Could not deserialize key data. The data may be in an incorrect format, it may be encrypted with an unsupported algorithm, or it may be an unsupported key type (e.g. EC curves with explicit parameters).', [<OpenSSLError(code=503841036, lib=60, reason=524556, reason_text=unsupported)>])

Additional Information:

Molecule version: 24.2.0
Ansible version: 2.6.5

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

No branches or pull requests

1 participant