HewlettPackard / HewlettPackard/monkeyble

Not Able to Access Default Variables

Open
#63 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
134
Forks
15
PR merge metrics
No merged PRs in 30d

Description

I'm not sure if I'm doing something wrong, but I can't seem to get Monkeyble to read my role's **default** variables.
Here's a simplified POC:

This **does** work:
```
---
monkeyble_scenarios:
validate_test_1:
name: Validate create gMSA
tasks_to_test:
- task: "Create a Group Managed Service Account (gMSA)."
mock:
config:
hpe.monkeyble.monkeyble_module:
consider_changed: true
result_dict:
object_guid: "00000000-0000-0000-0000-000000000000"
# test_input:
# - assert_equal:
# arg_name: identity
# expected: fake_identity

inputs:
app_id: fake_app_id
identity: fake_identity
mailing_list: fake_mailing_list
principals: fake_principal1,fake_principal2
```

This **does not** work (the difference being the `test_input`):

```
---
monkeyble_scenarios:
validate_test_1:
name: Validate create gMSA
tasks_to_test:
- task: "Create a Group Managed Service Account (gMSA)."
mock:
config:
hpe.monkeyble.monkeyble_module:
consider_changed: true
result_dict:
object_guid: "00000000-0000-0000-0000-000000000000"
test_input:
- assert_equal:
arg_name: identity
expected: fake_identity

inputs:
app_id: fake_app_id
identity: fake_identity
mailing_list: fake_mailing_list
principals: fake_principal1,fake_principal2
```

```
╰─± ANSIBLE_CONFIG="/tmp/ansible.cfg" ansible-playbook tests/playbooks/test_create_gmsa.yml -e @tests/monkeyble.yml -e monkeyble_scenario=validate_test_1
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Verify the role.] **************************************************************************************************************************************************************************************************************
🐵 Starting Monkeyble callback 1.7.1
monkeyble_scenario: validate_test_1
Monkeyble scenario: Validate create gMSA

TASK [active_directory : Validating arguments against arg spec 'create_gmsa' - Creates a Group Managed Service Account (gMSA)] *******************************************************************************************************
ok: [localhost]

TASK [active_directory : Create a Group Managed Service Account (gMSA).] *************************************************************************************************************************************************************
[WARNING]: Callback dispatch 'v2_runner_on_start' failed for plugin 'ansible_collections.hpe.monkeyble.plugins.callback.monkeyble_callback': 'active_directory' is undefined

Callback dispatch 'v2_runner_on_start' failed for plugin 'ansible_collections.hpe.monkeyble.plugins.callback.monkeyble_callback'.

<<< caused by >>>

'active_directory' is undefined
Origin:

2 - name: Create a Group Managed Service Account (gMSA).
3 microsoft.ad.service_account:
4 allowed_to_retrieve_password: "{{ active_directory.gmsa.allowed_to_retrieve_password }}"
^ column 35

[ERROR]: Task failed: Action failed: The module interpreter '/usr/bin/pwsh' was not found.

Task failed: Action failed.
Origin:

1 ---
2 - name: Create a Group Managed Service Account (gMSA).
^ column 3

<<< caused by >>>

The module interpreter '/usr/bin/pwsh' was not found. Consider overriding the configured interpreter path for this host. See stdout/stderr for the returned output.

fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "/bin/sh: /usr/bin/pwsh: No such file or directory\n", "module_stdout": "", "msg": "The module interpreter '/usr/bin/pwsh' was not found.", "rc": 127}
```

The second one works if I tack on a `-e @defaults/main.yml`. `active_directory` is defined here. Keys aside, even having it defined as an empty dict results in the same error without omitting the `test_input` or tacking on the flag.

```
╰─± ANSIBLE_CONFIG="/tmp/ansible.cfg" ansible-playbook tests/playbooks/test_create_gmsa.yml -e @tests/monkeyble.yml -e monkeyble_scenario=validate_test_1 -e @defaults/main.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Verify the role.] **************************************************************************************************************************************************************************************************************
🐵 Starting Monkeyble callback 1.7.1
monkeyble_scenario: validate_test_1
Monkeyble scenario: Validate create gMSA

TASK [active_directory : Validating arguments against arg spec 'create_gmsa' - Creates a Group Managed Service Account (gMSA)] *******************************************************************************************************
ok: [localhost]

TASK [active_directory : Create a Group Managed Service Account (gMSA).] *************************************************************************************************************************************************************
🙈 Monkeyble test input passed ✔
{"monkeyble_passed_test": [{"test_name": "assert_equal", "tested_value": "fake_identity", "expected": "fake_identity"}], "monkeyble_failed_test": []}
🙉 Monkeyble mock module - Before: 'microsoft.ad.service_account' Now: 'hpe.monkeyble.monkeyble_module'
changed: [localhost]

PLAY RECAP ***************************************************************************************************************************************************************************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

🐵 Monkeyble - ALL TESTS PASSED ✔ - scenario: Validate create gMSA
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue with tests/playbooks/test_create_gmsa.yml and tests/monkeyble.yml, comparing runs with and without defaults/main.yml. Start by reading the Monkeyble callback at ansible_collections.hpe.monkeyble.plugins.callback.monkeyble_callback and trace how test_input evaluates role variables; done means active_directory is available without the extra defaults file and the assertion passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.