我想使用ansible向Linux服务器“Ubuntu 18.04lts”上的“tuser”添加一个密钥对,以避免基于密码的登录。所以我在 yml 剧本文件中成功地尝试了这种方式:
- name: Set authorized key for tuser
become: yes
authorized_key:
user: tuser
state: present
key: "{{ lookup('file', '/home/rogg/.ssh/id_rsa.pub') }}"
好吧,但是当我尝试在 key 中使用其他位置时:
- name: Set authorized key for tuser
become: yes
authorized_key:
user: tuser
state: present
key: "{{ role_path }}/files/csbin_keys/id_rsa.pub"
我得到:
"msg": "指定的密钥无效
我已经使用 {{ role_path }} 复制其他文件并且可以正常工作,但是在这个键中它没有
authorized_key
模块文档摘录:
=
key
SSH 公钥,作为字符串或(自 1.9 起)url ( https://github.com/username.keys )
在您的第一个示例中,lookup('file', '/home/rogg/.ssh/id_rsa.pub')
读取文件/home/rogg/.ssh/id_rsa.pub
并将其内容作为key
值提供。
在您的第二个示例中,您尝试将文件路径作为key
值提供。
用查找替换它:
lookup('file', role_path+'/files/csbin_keys/id_rsa.pub')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句