Ansible 期望模块错误

Ansible expect module error

我使用 Ansible 2.2.1.0

我尝试通过命令使用 ansible expect 模块:

expect:
    command: set password of database
    responses:
        Admin Password for db_name: 'admin'
        Admin Password Confirmation: 'admin'

我收到此错误:

fatal: [subdomain.xxxx.com]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Connection to sante.c3-bs.com closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible_ys2qrkdy/ansible_module_expect.py\", line 237, in \r\n main()\r\n File \"/tmp/ansible_ys2qrkdy/ansible_module_expect.py\", line 149, in main\r\n response = u'%s\n' % value.rstrip('\n').decode()\r\nAttributeError: 'str' object has no attribute 'decode'\r\n", "msg": "MODULE FAILURE"}

我不明白这个错误有人可以帮助我并给我权利 expect 命令的响应或正确语法?

[编辑] **我在这里给出所有命令:

- name: Configure tryton database
become: yes
become_method: sudo
become_user: root
expect:
    command: su - gnuhealth -c "python3 /home/gnuhealth/gnuhealth/tryton/server/trytond-4.2.6/bin/trytond-admin -c /home/gnuhealth/gnuhealth/tryton/server/config/trytond.conf -d db_name --all"
    responses:
        (?i)Admin Password for db_name: "admin"
        (?i)Admin Password Confirmation: "admin"

我用的是Python2.7.9

简单的修复似乎是使用更新的 ansible 版本。这个或类似的东西似乎在 2.4 版中得到修复 - https://github.com/ansible/ansible/pull/24269

如果您的系统没有提供新版本,您可以使用pip 安装更新的版本。请记住先卸载系统包。