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

HAProxy module does not work with python3 interpreter #34811

Closed
newsletter2go opened this issue Jan 12, 2018 · 5 comments
Closed

HAProxy module does not work with python3 interpreter #34811

newsletter2go opened this issue Jan 12, 2018 · 5 comments
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. module This issue/PR relates to a module. net_tools Net-tools category python3 support:community This issue/PR relates to code supported by the Ansible community.

Comments

@newsletter2go
Copy link

ISSUE TYPE
  • Bug Report
COMPONENT NAME

HAProxy module

ANSIBLE VERSION
ansible 2.4.0.0
  config file = /home/user/development/provisioner-reloaded/ansible.cfg
  configured module search path = [u'/home/user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12 (default, Nov 20 2017, 18:23:56) [GCC 5.4.0 20160609]
CONFIGURATION
ANSIBLE_SSH_ARGS(/home/user/development/provisioner-reloaded/ansible.cfg) = -o ForwardAgent=yes
DEFAULT_LOG_PATH(/home/user/development/provisioner-reloaded/ansible.cfg) = /home/user/development/provisioner-reloaded/ansible.log
HOST_KEY_CHECKING(/home/user/development/provisioner-reloaded/ansible.cfg) = False
OS / ENVIRONMENT

Ansible OS: Ubuntu 16.04
Managed OS: Ubuntu 16.04

SUMMARY

When using python3 as ansible interpreter the haproxy fails while setting the backend to a specific state.

STEPS TO REPRODUCE
- name: Set MySQL backend to maintenance state in HAProxy
  haproxy:
    state: disabled
    host: db-mysql
    backend: mysql_cluster
    socket: /var/run/haproxy.sock
    shutdown_sessions: true

It works when no specific ansible interpreter is set, which means that python 2.7 is used. When setting

ansible_python_interpreter: /usr/bin/python3

in the host vars or group vars before, you get the error shown below. The issue seems to be here https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/net_tools/haproxy.py#L254 .

EXPECTED RESULTS
changed: [managed-host] => {"changed": true, "command": ["get weight mysql_cluster/db-mysql; disable server mysql_cluster/db-mysql; shutdown sessions server mysql_cluster/db-mysql"], "failed": false, "output": ["1 (initial 1)"], "state_after": [{"scur": "0", "status": "MAINT", "weight": "1"}], "state_before": [{"scur": "0", "status": "DOWN", "weight": "1"}]}
ACTUAL RESULTS
fatal: [managed-host]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Connection to 192.168.57.101 closed.\r\n", "module_stdout": "\r\nTraceback (most recent call last):\r\n  File \"/tmp/ansible_28dmn_55/ansible_module_haproxy.py\", line 454, in <module>\r\n    main()\r\n  File \"/tmp/ansible_28dmn_55/ansible_module_haproxy.py\", line 450, in main\r\n    ansible_haproxy.act()\r\n  File \"/tmp/ansible_28dmn_55/ansible_module_haproxy.py\", line 399, in act\r\n    state_before = self.get_state_for(self.backend, self.host)\r\n  File \"/tmp/ansible_28dmn_55/ansible_module_haproxy.py\", line 330, in get_state_for\r\n    data = self.execute('show stat', 200, False).lstrip('# ')\r\n  File \"/tmp/ansible_28dmn_55/ansible_module_haproxy.py\", line 254, in execute\r\n    self.client.sendall('%s\\n' % cmd)\r\nTypeError: a bytes-like object is required, not 'str'\r\n", "msg": "MODULE FAILURE", "rc": 0}
@ansibot
Copy link
Contributor

ansibot commented Jan 12, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Jan 12, 2018

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug_report module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. net_tools Net-tools category python3 support:community This issue/PR relates to code supported by the Ansible community. labels Jan 12, 2018
@sivel sivel removed the needs_triage Needs a first human triage before being processed. label Jan 15, 2018
@sivel
Copy link
Member

sivel commented Jan 15, 2018

Easier to read traceback:

Traceback (most recent call last):
  File \"/tmp/ansible_28dmn_55/ansible_module_haproxy.py\", line 454, in <module>
    main()
  File \"/tmp/ansible_28dmn_55/ansible_module_haproxy.py\", line 450, in main
    ansible_haproxy.act()
  File \"/tmp/ansible_28dmn_55/ansible_module_haproxy.py\", line 399, in act
    state_before = self.get_state_for(self.backend, self.host)
  File \"/tmp/ansible_28dmn_55/ansible_module_haproxy.py\", line 330, in get_state_for
    data = self.execute('show stat', 200, False).lstrip('# ')
  File \"/tmp/ansible_28dmn_55/ansible_module_haproxy.py\", line 254, in execute
    self.client.sendall('%s\\n' % cmd)
TypeError: a bytes-like object is required, not 'str'

@sivel sivel added this to TODO in Python 3 compatibility Jan 15, 2018
ravibhure added a commit to ravibhure/ansible that referenced this issue Jan 22, 2018
@ravibhure
Copy link
Contributor

@newsletter2go Thanks for reporting the issue. I update the PR (#35176)

@sivel looking to merge it soon.

ravibhure added a commit to ravibhure/ansible that referenced this issue Jan 23, 2018
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 1, 2018
@abadger abadger removed this from TODO in Python 3 compatibility Mar 5, 2018
abadger pushed a commit to abadger/ansible that referenced this issue Mar 22, 2018
* Fix python3 interpreter issue (ansible#34811)

* Update ansible.module_utils._text (ansible#34811)

* Convert to text later to account for multibyte characters
abadger pushed a commit to abadger/ansible that referenced this issue Mar 22, 2018
* Fix python3 interpreter issue (ansible#34811)

* Update ansible.module_utils._text (ansible#34811)

* Convert to text later to account for multibyte characters

(cherry picked from commit 340064b)
@abadger
Copy link
Contributor

abadger commented Mar 22, 2018

#35176 has been merged. Closing this as fixed in devel. I've also created a backport request: #37791 for it to be fixed in 2.5.

@abadger abadger closed this as completed Mar 22, 2018
@abadger abadger moved this from TODO to Done in Python 3 compatibility Mar 22, 2018
nitzmahone pushed a commit that referenced this issue Mar 29, 2018
* Fix python3 interpreter issue (#34811) (#35176)

* Fix python3 interpreter issue (#34811)

* Update ansible.module_utils._text (#34811)

* Convert to text later to account for multibyte characters

(cherry picked from commit 340064b)

* Add a changelog fragment for haproxy python3 fix
abadger pushed a commit that referenced this issue Mar 29, 2018
* Fix python3 interpreter issue (#34811)

* Update ansible.module_utils._text (#34811)

* Convert to text later to account for multibyte characters

(cherry picked from commit 340064b)
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. module This issue/PR relates to a module. net_tools Net-tools category python3 support:community This issue/PR relates to code supported by the Ansible community.
Projects
No open projects
Development

No branches or pull requests

5 participants