【问题标题】:ansible pexpect module with prompt coming on the next line and more than one promptansible pexpect 模块,提示出现在下一行并且有多个提示
【发布时间】:2020-04-03 00:05:28
【问题描述】:

我有一个脚本提示我输入两次密码,但提示出现在下一行,如下所示:-

Password: (I enter the Password here) Re-enter Password: (I enter the same Password here)

我正在尝试使用 Ansible pexpect 模块自动执行此操作,但我有一些无法正常工作的东西:-

- name: myscript --setup-users
  become: yes
  become_user: someadmin
  expect:
    command: 'myscript --setup-users'
    responses:
      "Password:": "somepassword"
      "Re-enter Password:": "somepassword"
  args:
    chdir: /home/someadmin/
  when:  someuser_out.stdout.find("someuser") == -1

我正在检查“someuser”在此播放之前是否存在。

此代码无效。

请帮忙

【问题讨论】:

    标签: python-3.x ansible pexpect


    【解决方案1】:

    让它与“\r\n”一起工作。 代码更改如下:-

    - name: myscript --setup-users
      become: yes
      become_user: someadmin
      expect:
        command: 'myscript --setup-users'
        responses:
          "password:": "somepassword"   #password for first prompt
          "\r\n:": "someotherpassword"  #password for second prompt which comes in the next line
          "\r\n:": "someotherpassword"  #same as above
      args:
        chdir: /home/someadmin/
      when:  someuser_out.stdout.find("someuser") == -1
    

    【讨论】:

      猜你喜欢
      • 2017-02-20
      • 2018-10-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-06
      相关资源
      最近更新 更多