theforeman / foreman-ansible-modules

Ansible modules for interacting with the Foreman API and various plugin APIs such as Katello
GNU General Public License v3.0
147 stars 163 forks source link

Module setting of validate_certs is ignored for Apypie module when using Vagrant #285

Closed ephracis closed 5 years ago

ephracis commented 5 years ago
SUMMARY

When executing Ansible via Vagrant the module setting validate_certs: False is ignored.

ISSUE TYPE
ANSIBLE VERSION
2.8.0
KATELLO/FOREMAN VERSION
1.21.3
NAILGUN VERSION
0.32.0
STEPS TO REPRODUCE

Execute Ansible via Vagrant against a self-signed Foreman with validate_certs set to False.

EXPECTED RESULTS

The module is executed properly.

ACTUAL RESULTS

Failed to connect to Foreman server: HTTPSConnectionPool(host='foreman.example.com', port=443): Max retries exceeded with url: /api/status (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))

CAUSE

This is because of how the verify flag is passed from Apypie into Pythons requests.

Right now the value for validate_certs is set as a property on the request object. When session.request() is executed it will do the following in merge_environment_settings in sessions.py:

The request is then made but with the session property of verify overridden.

SOLUTION

Pass the verify as an argument instead of setting it as merely a property on the session object. This will make sure it is honored properly when set to False even when there are environment variables.

I have a PR here which does this in Apypie: https://github.com/Apipie/apypie/pull/25

evgeni commented 5 years ago

Thanks! I've merged the PR to apypie. Should probably release a new version soon and then close this by requiring the new version.

evgeni commented 5 years ago

apypie 0.0.2 is available, closing this now