【问题标题】:unable to add SSH Key on Remote Server with Ansible无法使用 Ansible 在远程服务器上添加 SSH 密钥
【发布时间】:2016-01-08 22:10:57
【问题描述】:

我正在使用Ansible 并尝试将SSH Key 从我的服务器放到另一个远程服务器。

这是我的代码。

- name: Add RSA key to the remote host 
  authorized_key:
    user:
      name:"{{ item.user }}"
    key:"{{ lookup('file', '/home/ansible/.ssh/id_rsa.pub') }}"
    path:"/home/{{ item.username }}/.ssh/authorized_keys"
  when: item.get('state', 'present') == 'present'
  with_items: USER_LIST

每次尝试执行时都会出现以下错误。

ERROR: Syntax Error while loading YAML script, /home/ansible/public_html/ansible/roles/user/tasks/main.yml

注意:错误可能实际出现在该位置之前:第 39 行第 5 列

【问题讨论】:

    标签: ssh yaml ansible ansible-playbook


    【解决方案1】:

    你的语法错误,试试这个:

    - name: Add RSA key to the remote host 
      authorized_key:
        user: "{{ item.user }}"
        key: "{{ lookup('file', '/home/ansible/.ssh/id_rsa.pub') }}"
        path: "/home/{{ item.username }}/.ssh/authorized_keys"
      when: item.get('state', 'present') == 'present'
      with_items: USER_LIST
    

    【讨论】:

      猜你喜欢
      • 2013-06-28
      • 2013-09-12
      • 1970-01-01
      • 2022-07-11
      • 1970-01-01
      • 2023-02-06
      • 2014-11-29
      • 2012-11-26
      • 1970-01-01
      相关资源
      最近更新 更多