# Buggy code
def __init__(self, module):
    LdapGeneric.__init__(self, module)

    # Shortcuts
    self.name = self.module.params["name"]
    self.state = self.module.params["state"]

    # Normalize values
    if isinstance(self.module.params["values"], list):
        self.values = map(str, self.module.params["values"])
    else:
        self.values = [str(self.module.params["values"])]


# Traceback (TypeError)
TASK [ldap : Change access to "cn=config"] **********************************************************************************************************
task path: /opt/minidc/playbooks/roles/ldap/tasks/main.yml:71
Using module file /opt/minidc/python-venv/lib/python3.6/site-packages/ansible/modules/net_tools/ldap/ldap_attr.py
<10.10.0.207> ESTABLISH SSH CONNECTION FOR USER: root
<10.10.0.207> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ControlPath=/root/.ansible/cp/ecadde0115 10.10.0.207 '/bin/sh -c '"'"'echo ~ &amp;&amp; sleep 0'"'"''
<10.10.0.207> (0, b'/root\n', b'OpenSSH_7.6p1 Ubuntu-4, OpenSSL 1.0.2n  7 Dec 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 13705\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<10.10.0.207> ESTABLISH SSH CONNECTION FOR USER: root
<10.10.0.207> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ControlPath=/root/.ansible/cp/ecadde0115 10.10.0.207 '/bin/sh -c '"'"'( umask 77 &amp;&amp; mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1525199053.115565-74792575806862 `" &amp;&amp; echo ansible-tmp-1525199053.115565-74792575806862="` echo /root/.ansible/tmp/ansible-tmp-1525199053.115565-74792575806862 `" ) &amp;&amp; sleep 0'"'"''
<10.10.0.207> (0, b'ansible-tmp-1525199053.115565-74792575806862=/root/.ansible/tmp/ansible-tmp-1525199053.115565-74792575806862\n', b'OpenSSH_7.6p1 Ubuntu-4, OpenSSL 1.0.2n  7 Dec 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 13705\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<10.10.0.207> PUT /root/.ansible/tmp/ansible-local-18875s48nuhbc/tmpxqvbyvz7 TO /root/.ansible/tmp/ansible-tmp-1525199053.115565-74792575806862/ldap_attr.py
<10.10.0.207> SSH: EXEC sftp -b - -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ControlPath=/root/.ansible/cp/ecadde0115 '[10.10.0.207]'
<10.10.0.207> (0, b'sftp> put /root/.ansible/tmp/ansible-local-18875s48nuhbc/tmpxqvbyvz7 /root/.ansible/tmp/ansible-tmp-1525199053.115565-74792575806862/ldap_attr.py\n', b'OpenSSH_7.6p1 Ubuntu-4, OpenSSL 1.0.2n  7 Dec 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 13705\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug2: Remote version: 3\r\ndebug2: Server supports extension "posix-rename@openssh.com" revision 1\r\ndebug2: Server supports extension "statvfs@openssh.com" revision 2\r\ndebug2: Server supports extension "fstatvfs@openssh.com" revision 2\r\ndebug2: Server supports extension "hardlink@openssh.com" revision 1\r\ndebug2: Server supports extension "fsync@openssh.com" revision 1\r\ndebug3: Sent message fd 3 T:16 I:1\r\ndebug3: SSH_FXP_REALPATH . -> /root size 0\r\ndebug3: Looking up /root/.ansible/tmp/ansible-local-18875s48nuhbc/tmpxqvbyvz7\r\ndebug3: Sent message fd 3 T:17 I:2\r\ndebug3: Received stat reply T:101 I:2\r\ndebug1: Couldn\'t stat remote file: No such file or directory\r\ndebug3: Sent message SSH2_FXP_OPEN I:3 P:/root/.ansible/tmp/ansible-tmp-1525199053.115565-74792575806862/ldap_attr.py\r\ndebug3: Sent message SSH2_FXP_WRITE I:4 O:0 S:32768\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 4 32768 bytes at 0\r\ndebug3: Sent message SSH2_FXP_WRITE I:5 O:32768 S:32768\r\ndebug3: Sent message SSH2_FXP_WRITE I:6 O:65536 S:2784\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 5 32768 bytes at 32768\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 6 2784 bytes at 65536\r\ndebug3: Sent message SSH2_FXP_CLOSE I:4\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<10.10.0.207> ESTABLISH SSH CONNECTION FOR USER: root
<10.10.0.207> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ControlPath=/root/.ansible/cp/ecadde0115 10.10.0.207 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1525199053.115565-74792575806862/ /root/.ansible/tmp/ansible-tmp-1525199053.115565-74792575806862/ldap_attr.py &amp;&amp; sleep 0'"'"''
<10.10.0.207> (0, b'', b'OpenSSH_7.6p1 Ubuntu-4, OpenSSL 1.0.2n  7 Dec 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 13705\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<10.10.0.207> ESTABLISH SSH CONNECTION FOR USER: root
<10.10.0.207> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ControlPath=/root/.ansible/cp/ecadde0115 -tt 10.10.0.207 '/bin/sh -c '"'"'/usr/bin/env python3 /root/.ansible/tmp/ansible-tmp-1525199053.115565-74792575806862/ldap_attr.py &amp;&amp; sleep 0'"'"''
<10.10.0.207> (1, b'\r\n{"msg": "Attribute action failed.", "details": "(\'Tuple_to_LDAPMod(): expected a byte string in the list\', \'to * by dn.exact=cn=admin,dc=tech-tips,dc=fr manage by * break\')", "exception": "Traceback (most recent call last):\\n  File \\"/tmp/ansible_mv919afh/ansible_module_ldap_attr.py\\", line 352, in main\\n    ldap.connection.modify_s(ldap.dn, modlist)\\n  File \\"/usr/local/lib/python3.6/dist-packages/ldap/ldapobject.py\\", line 629, in modify_s\\n    return self.modify_ext_s(dn,modlist,None,None)\\n  File \\"/usr/local/lib/python3.6/dist-packages/ldap/ldapobject.py\\", line 601, in modify_ext_s\\n    msgid = self.modify_ext(dn,modlist,serverctrls,clientctrls)\\n  File \\"/usr/local/lib/python3.6/dist-packages/ldap/ldapobject.py\\", line 598, in modify_ext\\n    return self._ldap_call(self._l.modify_ext,dn,modlist,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls))\\n  File \\"/usr/local/lib/python3.6/dist-packages/ldap/ldapobject.py\\", line 313, in _ldap_call\\n    result = func(*args,**kwargs)\\nTypeError: (\'Tuple_to_LDAPMod(): expected a byte string in the list\', \'to * by dn.exact=cn=admin,dc=tech-tips,dc=fr manage by * break\')\\n", "failed": true, "invocation": {"module_args": {"dn": "olcDatabase={0}config,cn=config", "name": "olcAccess", "values": "to * by dn.exact=cn=admin,dc=tech-tips,dc=fr manage by * break", "state": "exact", "validate_certs": false, "bind_pw": "", "server_uri": "ldapi:///", "start_tls": false, "bind_dn": null, "params": null}}}\r\n', b'OpenSSH_7.6p1 Ubuntu-4, OpenSSL 1.0.2n  7 Dec 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 13705\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\nShared connection to 10.10.0.207 closed.\r\n')
<10.10.0.207> ESTABLISH SSH CONNECTION FOR USER: root
<10.10.0.207> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=root -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o ControlPath=/root/.ansible/cp/ecadde0115 10.10.0.207 '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1525199053.115565-74792575806862/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'"'"''
<10.10.0.207> (0, b'', b'OpenSSH_7.6p1 Ubuntu-4, OpenSSL 1.0.2n  7 Dec 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 13705\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_mv919afh/ansible_module_ldap_attr.py", line 352, in main
ldap.connection.modify_s(ldap.dn, modlist)
File "/usr/local/lib/python3.6/dist-packages/ldap/ldapobject.py", line 629, in modify_s
return self.modify_ext_s(dn,modlist,None,None)
File "/usr/local/lib/python3.6/dist-packages/ldap/ldapobject.py", line 601, in modify_ext_s
msgid = self.modify_ext(dn,modlist,serverctrls,clientctrls)
File "/usr/local/lib/python3.6/dist-packages/ldap/ldapobject.py", line 598, in modify_ext
return self._ldap_call(self._l.modify_ext,dn,modlist,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls))
File "/usr/local/lib/python3.6/dist-packages/ldap/ldapobject.py", line 313, in _ldap_call
result = func(*args,**kwargs)
TypeError: ('Tuple_to_LDAPMod(): expected a byte string in the list', 'to * by dn.exact=cn=admin,dc=tech-tips,dc=fr manage by * break')

fatal: [ubuldap01]: FAILED! => {
"changed": false,
"details": "('Tuple_to_LDAPMod(): expected a byte string in the list', 'to * by dn.exact=cn=admin,dc=tech-tips,dc=fr manage by * break')",
"invocation": {
"module_args": {
"bind_dn": null,
"bind_pw": "",
"dn": "olcDatabase={0}config,cn=config",
"name": "olcAccess",
"params": null,
"server_uri": "ldapi:///",
"start_tls": false,
"state": "exact",
"validate_certs": false,
"values": "to * by dn.exact=cn=admin,dc=tech-tips,dc=fr manage by * break"
}
},
"msg": "Attribute action failed."
}
to retry, use: --limit @/opt/minidc/playbooks/setup-ldap.retry

# Fixed code
def __init__(self, module):
    LdapGeneric.__init__(self, module)

    # Shortcuts
    self.name = self.module.params["name"]
    self.state = self.module.params["state"]

    # Normalize values
    if isinstance(self.module.params["values"], list):
        self.values = map(to_bytes, self.module.params["values"])
    else:
        self.values = [to_bytes(self.module.params["values"])]