Open madrover opened 4 years ago
Can I have some guidance on this one, please?
Please try Ansible 2.8.8; Ansible 2.9 isn't fully supported yet. Also if you want you can try my patch that fixes some things as well: https://github.com/dw/mitogen/pull/658 It mainly fixes ansible_python_interpreter
discovery but touches some other stuff too. After my patch lands I hope to spend some time getting Ansible 2.9 supported fully.
The misbehavior can be reproduced in Ansible 2.8.8. However, I have determined what's causing the issue; we have a role which includes a library which implements a task that we use to validate a license that we use to deploy a component.
The module is called this way:
- name: Test that license has not expired
license_check:
license_file: "{{ license_file }}"
delegate_to: localhost
And the library content is:
#!/usr/bin/python
from ansible.module_utils.basic import AnsibleModule
from ansible.utils.display import Display
from datetime import datetime
from datetime import timedelta
import re
import os
def main():
result = dict(
changed = False,
warnings = [],
renewal_date = ''
)
module = AnsibleModule(
argument_spec = dict(
license_file = dict(required=True),
warning_weeks = dict(required=False, type='int', default=12)
),
supports_check_mode=True
)
pattern = re.compile("^key.renewal=(.*)")
try:
for line in open(module.params['license_file']):
for match in re.finditer(pattern, str(line)):
expiry_date = datetime.strptime(match.group(1), '%Y%m%d')
result['renewal_date'] = expiry_date.strftime('%Y-%m-%d')
expiry_window = expiry_date - timedelta(weeks=module.params['warning_weeks'])
now = datetime.now()
if expiry_date < now:
fail_msg = 'The license expired on ' + expiry_date.strftime('%d %b %Y') + '.'
module.fail_json(msg = fail_msg)
elif expiry_window < now:
fail_msg = 'The license is due to expire on ' + expiry_date.strftime('%d %b %Y') + '.'
result['warnings'].append(fail_msg)
except IOError:
module.fail_json(msg = 'Could not open the requested file: ' + module.params['license_file'])
module.exit_json(**result)
if __name__ == '__main__':
main();
If we remove the call to that module then the playbook executes without problems.
Thanks for the info 👍 I should have time in the next few days to repro on my end with your custom module and see if I can fix your issue
I'm working on this here: https://github.com/s1113950/mitogen-test/commit/6029980ad0fbada29c33afc219f0fd494a409e4f , running with make custom-lib-unpickle-test
. I get a different error than you do though, possibly because I'm not targeting a centos6 machine yet. Don't have time to work on this anymore today, but plan on tackling it more soon.
Do you have a specific warning_weeks
value or license_file
I should use to repro?
@madrover
Try removing this import from your license_file
:
from ansible.utils.display import Display
It works for me targeting a centos6 docker host from my Mac (closest setup I could make):
TASK [run_test : Create license file on docker host] *************************************************************************************************************
task path: pathHere
changed: [localhost -> testMitogen] => {"ansible_facts": {}, "changed": true, "cmd": "echo \"LICENSE\" > /tmp/license_file.txt", "delta": "0:00:00.003377", "end":
"2020-03-26 07:09:30.639485", "rc": 0, "start": "2020-03-26 07:09:30.636108", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
TASK [run_test : Test that license has not expired] **************************************************************************************************************
task path: pathHere
ok: [localhost -> testMitogen] => {"ansible_facts": {}, "changed": false, "renewal_date": ""}
via
- name: Create license file on docker host
shell: echo "LICENSE" > /tmp/license_file.txt
- name: Test that license has not expired
license_check:
license_file: /tmp/license_file.txt
with a delegate_to
pointing to my centos6 container.
I tested with a license file that just contained the word LICENSE
in it since I'm not sure what kind of license file you're using.
If that doesn't work for you then I'll need a sample license_file
and warning_weeks
value to get a more precise test :)
While I'm unsure if it's the same issue, the same message was raised for me on Python 3.11.6 and fixed with minor version bumps, so if someone else runs into it:
Hi When trying to execute any ansible command, either adhoc or on playbook, against some hosts it fais with the following error:
This error is reproducible only when using become, otherwise it seems to work.
Thanks!
module**utils
loaded? No