无法使用 Ansible 在远程服务器上添加 SSH 密钥
unable to add SSH Key on Remote Server with Ansible
我正在使用 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列
你的语法有误,试试这个:
- 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
我正在使用 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列
你的语法有误,试试这个:
- 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