Ansible使用将ssh公钥从一个帐户复制到另一个帐户
我面临在远程服务器上的两个帐户之间复制ssh密钥的问题。我有一个名为“rmt”的远程服务器,在rmt上我有一个名为“clado”的帐户,我想使用Ansible将Ansible使用将ssh公钥从一个帐户复制到另一个帐户,ansible,Ansible,我面临在远程服务器上的两个帐户之间复制ssh密钥的问题。我有一个名为“rmt”的远程服务器,在rmt上我有一个名为“clado”的帐户,我想使用Ansible将/root/.ssh/authorized_keys(在rmt上)复制到/home/clado/.ssh/authorized_keys(在rmt上) 我得到了以下示例代码: - name: Set authorized key in alternate location authorized_key: user: charl
/root/.ssh/authorized_keys
(在rmt上)复制到/home/clado/.ssh/authorized_keys
(在rmt上)
我得到了以下示例代码:
- name: Set authorized key in alternate location
authorized_key:
user: charlie
state: present
key: "{{ lookup('file', '/home/charlie/.ssh/id_rsa.pub') }}"
但是它使用的是本地/home/charlie/.ssh/id\u rsa.pub
但是它使用的是本地('/home/charlie/.ssh/id_rsa.pub')
所有查找插件都在Ansible控制计算机上本地工作
您可以通过以下方式获取远程文件的内容,例如:
- name: Fetch authorized key from alternate location
slurp:
src: /home/other_user/.ssh/id_rsa.pub
register: slurped_key_b64
- name: Ensure the fetched key is set for charlie
authorized_key:
user: charlie
state: present
key: "{{ slurped_key_b64.content | b64decode }}"
自定义详细信息,因为您的描述和代码不匹配
但从系统管理的角度来看,这种流程通常没有多大意义。从控制机器分配钥匙
但是它使用的是本地('/home/charlie/.ssh/id_rsa.pub')
所有查找插件都在Ansible控制计算机上本地工作
您可以通过以下方式获取远程文件的内容,例如:
- name: Fetch authorized key from alternate location
slurp:
src: /home/other_user/.ssh/id_rsa.pub
register: slurped_key_b64
- name: Ensure the fetched key is set for charlie
authorized_key:
user: charlie
state: present
key: "{{ slurped_key_b64.content | b64decode }}"
自定义详细信息,因为您的描述和代码不匹配
但从系统管理的角度来看,这种流程通常没有多大意义。从控制机器上分配钥匙。如果您是从机器上取钥匙的话
/root/.ssh/authorized
而不是取代家
/charlie/.ssh/id\u rsa.pub from/root/.ssh/authorized\u keys
和sudo一起做。使用been:true
任务中的参数。如果您从
/root/.ssh/authorized
而不是取代家
/charlie/.ssh/id\u rsa.pub from/root/.ssh/authorized\u keys
和sudo一起做。使用been:true
任务中的参数。如果您从/root/.ssh/authorized中选择它,则从/root/.ssh/id\u rsa.pub替换/root/.ssh/authorized\u keyd中的home/charlie/.ssh/id\u rsa.pub并使用sudo处理它。在您的任务中使用been:true参数。如果您从/root/.ssh/authorized中选取它,则从/root/.ssh/id\u rsa.pub替换/root/.ssh/authorized\u keyd中的home/charlie/.ssh/id\u rsa.pub并使用sudo处理它。在任务中使用been:true参数。