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

Feat: Adding Support For Environment Variables #684

Closed
wants to merge 6 commits into from

Conversation

aetherrealm
Copy link

@aetherrealm aetherrealm commented Nov 30, 2023

Change Summary

Currently the tools_cv.py does not accept environment variables when calling the connect method of the CvpClient class from cvprac.cvp_client. In AAPv2 (Ansible Tower) it is not possible to vault values in a sourced inventory. While you can move the token to host or group vars, this leaves the FQDN hardcoded into the inventory.

This change allows support for setting the host target or host delegation to localhost instead of to a CVP host, such that CVP and any associated vars can be removed from the inventory. A custom credential type in Ansible Tower can be created and the injector config can contain all of the environment variables required which can then be associated with a template.

The custom credential can be associated with a sourced inventory as well, however, the environment variables will be ignored by tools_cv.py if the CVP server is provided in inventory and referenced in the playbook.

README and CVP_Authentication were also updated to reflect this change.

Related Issue(s)

N/A

Component(s) name

affect all plugins

Proposed changes

The following environment variables will be accepted by tools_cv.py if CVP is omitted from inventory and is replaced with localhost in the playbook:

CVP_HOST
CVP_PORT
CVP_USER
CVP_PASS
CVP_TOKEN
CVP_CERT_VALIDATE (True / False)
CVP_CMD_TIMEOUT
CVP_CON_TIMEOUT

How to test

Keep CVP in inventory as is in your project and add all of the environment variables with their appropriate values above and you will see that the values in the inventory are still used.

Remove CVP from inventory and change reference to it in the playbook in question to localhost, environment variables will now be required instead.

CVP in inventory and playbook, and no environment variables.

All 3 cases tested successfully on multiple modules.

Checklist

User Checklist

  1. Delete CVP from inventory
  2. Update playbooks to reference locahost instead of cvp in host targeting and delegation
  3. Set environment variables on executing system (or leverage custom credential types and inject them into a template via credential association)
  4. Run the project

Repository Checklist

  • My code has been rebased from devel before I start
  • I have read the CONTRIBUTING document.
  • My change requires a change to the documentation and documentation have been updated accordingly. (check the box if not applicable)
  • I have updated molecule CI testing accordingly. (check the box if not applicable)

Adding support for environment variables.
Fixing parenthesis
Added AssertionError exception catch for module socket connection since if a host isn't provided in the play this will break.

Setting only environment variables the host needs to be set to localhost.
Removed type changes from module vars for successful validation.
Updating README to include supported environment variables.
Updated CVP-Authentication documentation to reference supported environment variables.
@github-actions github-actions bot added module_utils: cv_client cv_client implementation issue type: documentation Improvements or additions to documentation labels Nov 30, 2023
Copy link

github-actions bot commented Mar 4, 2024

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 15 days

@github-actions github-actions bot added the state: stale Staled issues waiting for closure label Mar 4, 2024
@github-actions github-actions bot closed this Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module_utils: cv_client cv_client implementation issue state: stale Staled issues waiting for closure type: documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant