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

Add proxy options to templates_import module #1795

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

adamlazik1
Copy link

Copy link
Member

@evgeni evgeni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have to pass IDs around, our abstraction layer can resolve entities for you :)

I've proposed changes (untested) that should do exactly that, treat "http_proxy" as an entity, and look it up via the API if passed.

plugins/modules/templates_import.py Outdated Show resolved Hide resolved
plugins/modules/templates_import.py Outdated Show resolved Hide resolved
tests/test_playbooks/tasks/templates_import.yml Outdated Show resolved Hide resolved
@evgeni
Copy link
Member

evgeni commented Nov 12, 2024

the diff looks good to me!
thanks!

@adamlazik1
Copy link
Author

Hey @evgeni , I tried the patch but it does not seem to work:

ansible-playbook -i ,localhost -c local -e foreman_username=admin -e foreman_password=changeme -e templates_import_http_proxy='https proxy' -e templates_import_http_proxy_policy=selected -e foreman_server_url=http://foreman-dev.example.com -e foreman_validate_certs=false test.yaml  --module-path='foreman-ansible-modules/plugins/modules'

PLAY [all] ***********************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Sync templates in from a git repo] *****************************************************************************************************************************************************************************************************
[WARNING]: You have configured a plain HTTP server URL. All communication will happen unencrypted.
fatal: [localhost]: FAILED! => {"changed": false, "error": {"message": "Couldn't find HttpProxy without an ID"}, "msg": "Error while performing import on templates: 422 Client Error: Unprocessable Content for url: http://foreman-dev.example.com/api/templates/import"}

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

The http proxy id param did not get passed to the API. Any idea what could be the issue?

@adamlazik1
Copy link
Author

adamlazik1 commented Nov 12, 2024

Hey @evgeni , I tried the patch but it does not seem to work:

ansible-playbook -i ,localhost -c local -e foreman_username=admin -e foreman_password=changeme -e templates_import_http_proxy='https proxy' -e templates_import_http_proxy_policy=selected -e foreman_server_url=http://foreman-dev.example.com -e foreman_validate_certs=false test.yaml  --module-path='foreman-ansible-modules/plugins/modules'

PLAY [all] ***********************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Sync templates in from a git repo] *****************************************************************************************************************************************************************************************************
[WARNING]: You have configured a plain HTTP server URL. All communication will happen unencrypted.
fatal: [localhost]: FAILED! => {"changed": false, "error": {"message": "Couldn't find HttpProxy without an ID"}, "msg": "Error while performing import on templates: 422 Client Error: Unprocessable Content for url: http://foreman-dev.example.com/api/templates/import"}

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

The http proxy id param did not get passed to the API. Any idea what could be the issue?

🤦 nevermind I forgot to update my test file. Yeah it works as intended so now I just wait for linked PR to get merged before I mark this ready for merge.

ansible-playbook -i ,localhost -c local -e foreman_username=admin -e foreman_password=changeme -e 'templates_import_http_proxy="https proxy"' -e templates_import_http_proxy_policy=selected -e foreman_server_url=http://foreman-dev.example.com -e foreman_validate_certs=false test.yaml  --module-path='foreman-ansible-modules/plugins/modules'

PLAY [all] ***********************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Sync templates in from a git repo] *****************************************************************************************************************************************************************************************************
[WARNING]: You have configured a plain HTTP server URL. All communication will happen unencrypted.
changed: [localhost]

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

@evgeni
Copy link
Member

evgeni commented Nov 12, 2024

🤦 nevermind I forgot to update my test file. Yeah it works as intended so now I just wait for linked PR to get merged before I mark this ready for merge.

Phew. Your PR to templates looks correct, and the same lookup works in many other places, so it would be very weird if it wouldn't work here.

@evgeni evgeni changed the title Add proxy options to template sync playbook Add proxy options to templates_import module Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants