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

Changes to make python3 compatible: #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Changes to make python3 compatible: #31

wants to merge 1 commit into from

Conversation

maj0rhav0c
Copy link

Fixed ansible-logrotate role to use python3 direct
Python3 deprecated iteritems - using items instead

ansible-logrotate/library/logrotate:

  • added encode('utf-8') to _compare_config
  • changed iteritems to items in _get_config (iteritems deprecated)

BACKGROUND:
using ansible 2.6.1, python 3.6.6
invoking ansible direct in python3 for ubuntu16, rather than installing python2 first
ansible-playbook extra_vars from CLI to invoke python3 direct:
ansible-playbook ansible-logrotate -i inventory_file.yml -e ansible_python_interpreter=/usr/bin/python3

Or from static inventory file:
logrotate16 ansible_ssh_host=192.168.60.5 ansible_python_interpreter=/usr/bin/python3

ansible-logrotate/library/logrotate:
- added encode('utf-8') to _compare_config
- changed iteritems to items in _get_config (iteritems deprecated)
@maj0rhav0c
Copy link
Author

Small change - discovered when re-writing our playbooks to use python3 rather than installing python2 first on ubuntu16+.

@maj0rhav0c
Copy link
Author

These were the errors I was receiving:

no iteritems

TASK [logrotate : apport] **********************************************************************************************
fatal: [logrotate16]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 192.168.60.5 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_5oo3_7cn/ansible_module_logrotate.py\", line 202, in <module>\r\n    main()\r\n  File \"/tmp/ansible_5oo3_7cn/ansible_module_logrotate.py\", line 195, in main\r\n    _add_config(module)\r\n  File \"/tmp/ansible_5oo3_7cn/ansible_module_logrotate.py\", line 162, in _add_config\r\n    config = _get_config(module)\r\n  File \"/tmp/ansible_5oo3_7cn/ansible_module_logrotate.py\", line 152, in _get_config\r\n    for (k, v) in scripts.iteritems()]\r\nAttributeError: 'dict' object has no attribute 'iteritems'\r\nSCRIPTS: {}\r\n", "msg": "MODULE FAILURE", "rc": 1}

after iterietms changed to items:

TASK [logrotate : apport] ***********************************************************************************************************************************************************
fatal: [logrotate16]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 192.168.60.5 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_jw65_weo/ansible_module_logrotate.py\", line 206, in <module>\r\n    main()\r\n  File \"/tmp/ansible_jw65_weo/ansible_module_logrotate.py\", line 199, in main\r\n    _add_config(module)\r\n  File \"/tmp/ansible_jw65_weo/ansible_module_logrotate.py\", line 168, in _add_config\r\n    if not _compare_config(config, config_path):\r\n  File \"/tmp/ansible_jw65_weo/ansible_module_logrotate.py\", line 123, in _compare_config\r\n    current_run_md5 = (hashlib.md5(config)).encode('utf-8').hexdigest()\r\nTypeError: Unicode-objects must be encoded before hashing\r\n", "msg": "MODULE FAILURE", "rc": 1}

jshprentz added a commit to jshprentz/ansible-logrotate that referenced this pull request Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant