将SSH密钥部署到服务器

将SSH密钥部署到服务器,ssh,ansible,ssh-keys,Ssh,Ansible,Ssh Keys,我有以下剧本: --- - name: provision toms keys hosts: ssh4.demo.com tasks: - name: ensure user tom is present user: name=tom state=present - name: ensure private key and public one are present copy: src=ssh_keys/tom dest=/.

我有以下剧本:

---
 - name: provision toms keys
    hosts: ssh4.demo.com
    tasks:
     - name: ensure user tom is present
       user: name=tom state=present

     - name: ensure private key and public one are present
       copy: src=ssh_keys/tom dest=/.ssh mode=0600
       with_items:
         - id_rsa.pub
         - id_rsa

 - name: provision toms public keys
    hosts: ssh1.demo.com

    sudo: yes

    tasks:

     - user: name=tom comment="Add tom" group=staff

     - name: Placing key
       authorized_key: user=tom key="{{ lookup('file', 'ssh_keys/tom/id_rsa.pub') }}"
我有一个本地目录,其中包含ssh公钥和私钥,如下所示:

./ssh_keys
./ssh_keys/david
./ssh_keys/david/id_rsa
./ssh_keys/david/id_rsa.pub
./ssh_keys/fred
./ssh_keys/fred/id_rsa
./ssh_keys/fred/id_rsa.pub
./ssh_keys/joe
./ssh_keys/joe/id_rsa
./ssh_keys/joe/id_rsa.pub
./ssh_keys/paul
./ssh_keys/paul/id_rsa
./ssh_keys/paul/id_rsa.pub
./ssh_keys/peter
./ssh_keys/peter/id_rsa
./ssh_keys/peter/id_rsa.pub
./ssh_keys/tom
./ssh_keys/tom/id_rsa
./ssh_keys/tom/id_rsa.pub
我需要创建一些剧本,可以用来将关键点推送到hosts字段中定义的各种主机

但是,.ssh密钥目录的创建不正确。i、 e.在id_rsa和id_rsa.pub目录下创建一个名为tom的目录

e、 g

有没有人有一个很好的例子

试试看:

 ---
 - name: provision toms keys
    hosts: ssh4.demo.com
    tasks:
     - name: ensure user tom is present
       user: name=tom state=present

     - name: ensure private key and public one are present
       copy: src=ssh_keys/tom/ dest=/.ssh mode=0600
您可以使用“tom/”复制整个目录tom或tom的内容。 另外,复制完整目录时,不需要指定文件

 ---
 - name: provision toms keys
    hosts: ssh4.demo.com
    tasks:
     - name: ensure user tom is present
       user: name=tom state=present

     - name: ensure private key and public one are present
       copy: src=ssh_keys/tom/ dest=/.ssh mode=0600