使用 `local_action` 运行 Ansible 模块时出现“sudo:未提供密码”

时间:2021-05-27 17:10:30

标签: ansible ansible-galaxy

我正在尝试使用 this github_key community module 将 SSH 公钥添加到 Github 帐户。

(我用 ansible-galaxy collection install community.general 安装了社区模块)

在我的任务列表中,我 -

  1. 阅读publickey
  2. 调用 github_key(使用 local_action)将该密钥添加到 Github 帐户

- name: Read SSH key for jeeves@github.com
  shell: 'cat /home/jeeves/.ssh/jeeves@github.com.pub'
  register: ssh_pub_key

- name: Upload SSH key for jeeves@github.com
  local_action:
    module: github_key
    name: 'Key for jeeves@my-server.dev'
    token: '{{ github_token }}'
    pubkey: '{{ ssh_pub_key.stdout }}'
    force: yes

当我运行它时得到这个错误(在 module_stderr 输出中):

[sudo via ansible, key=<REDACTED>] password:
sudo: no password was provided
sudo: 1 incorrect password attempt

我猜它找不到用户的 sudo 密码。

但我提供了一个 sudo 密码,在此之前还有 30 多个其他任务(此处未显示)能够成功执行命令。事实上,在我的剧本定义中,我使用了 become:

- hosts: all
  become: yes
  become_method: sudo
  become_user: root
  gather_facts: yes
  #...

我认为问题是由 local_action 引起的,因为它甚至在执行模块本身时也遇到问题。

谢谢!

0 个答案:

没有答案