Ansible - 登录到 heroku

Ansible - login to heroku

通常使用终端登录是这样的

sudo heroku login --interactive
Email: My email
Password: My password
Login Successful!

这是我的角色

- name: Heroku login
  expect:
    command: heroku login --interactive
    responses:
      (?i)Email: '{{ heroku_email }}'
      (?i)Password: '{{ heroku_password }}'

30秒后我得到了

fatal: [localhost]: FAILED! => {"changed": true, "cmd": "heroku login --interactive", "delta": "0:00:31.545693", "end": "2020-04-02 20:06:40.838040", "msg": "command exceeded timeout", "rc": null, "start": "2020-04-02 20:06:09.292347", "stdout": " \u001b[33m›\u001b[39m   Warning: heroku update available from \u001b[92m7.39.0\u001b[39m to \u001b[92m7.39.2\u001b[39m.\r\nheroku: Enter your login credentials\r\nEmail \u001b[33m[myemail@gmail.com]\u001b[39m: \u001b[2K\u001b[GPassword: ***********", "stdout_lines": [" \u001b[33m›\u001b[39m   Warning: heroku update available from \u001b[92m7.39.0\u001b[39m to \u001b[92m7.39.2\u001b[39m.", "heroku: Enter your login credentials", "Email \u001b[33m[myemail@gmail.com]\u001b[39m: \u001b[2K\u001b[GPassword: ***********"]}

有人知道我为什么会收到那个错误吗?

expect 模块的默认超时时间为 30 秒。从stdout可以看出expect对这两个提示都有响应

登录时间可能超过默认超时时间。增加任务的超时时间,

- name: Heroku login
  expect:
    command: heroku login --interactive
    responses:
      (?i)Email: '{{ heroku_email }}'
      (?i)Password: '{{ heroku_password }}'
    timeout: 300

我花了两天时间做了这个,我问了社区anisble,不幸的是没有成功。我做了一个替代退出,即使用 expect 脚本登录。它看起来像这样:

#!/usr/bin/expect

spawn heroku login -i

sleep 1

send "HEROKU_EMAIL";

send "\r"

sleep 1

send "HEROKU_PASSWORD"

sleep 1

send "\r"

sleep 2

interact

如果有人想要整个角色,请按照下面的link

https://github.com/BElluu/Ansible-Heroku-Deploy

#!/usr/bin/expect
spawn heroku login -i
expect -re "Email*"
send "EMAIL";
send "\r"
expect -re "Pass*"
send "PASSWORD";
sleep 1
send "\r"
interact