zoukankan      html  css  js  c++  java
  • ansible 批量推送公钥

    这里我们使用ansible的playbook 的功能来推送秘钥

    使用方法参见:http://blog.csdn.net/magedu_linux/article/details/48529645

    这里我们首先配置好hosts,比如说

    root@bigbao-VirtualBox:/etc/ansible/yml# cat /etc/ansible/hosts
    [sky_2]
    #sky1 ansible_ssh_host=10.10.20.2 ansible_ssh_port=102 ansible_ssh_user=root
    #sky2 ansible_ssh_host=10.10.20.2 ansible_ssh_port=103 ansible_ssh_user=root
    #sky3 ansible_ssh_host=10.10.20.2 ansible_ssh_port=104 ansible_ssh_user=root
    sky1 ansible_ssh_host=10.10.20.2 ansible_ssh_port=102 ansible_ssh_user=root ansible_ssh_pass="Abcd1234"
    sky2 ansible_ssh_host=10.10.20.2 ansible_ssh_port=103 ansible_ssh_user=root ansible_ssh_pass="Abcd1234"
    sky3 ansible_ssh_host=10.10.20.2 ansible_ssh_port=104 ansible_ssh_user=root ansible_ssh_pass="Abcd1234"
    
    这里我们 一定要把ansible_ssh_pass给加上,不然的话会报下面的错,这里我们可以配置完成之后,ansible_ssh_pass 给删除掉
    

     

    还有一个错误是

    这里我们修改一下ansible.cfg的配置文件

    host_key_checking = False把注释放开

    然后编写playbook

    这里使用到了authoried_keys模块
    估计背墙了,所以。。。。。
     

    authoried_keys模块参数介绍

    注意在推送playbook的时候我们要注意host 的格式(要有密码)

    修改ansible的hosts(Inventory)文件,如下图所示,格式:

    [主机名] [ssh连接账户] [ssh主机地址] [ssh连接账户对应的密码]

     

    验证一下公钥是不是传过去了

    我们看一下yml文件内容是

    root@bigbao-VirtualBox:/etc/ansible/yml# cat scp_key.yml 
    - hosts: sky_2
      remote_user: root
    
      tasks:
      - name: copy ssh key
        authorized_key:
          user: root
          key: "{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
    
  • 相关阅读:
    Computability 2: Gödel Number
    Computability 1: Computational Models
    Axiomatic Set Theory
    External Sorting Model
    Minimum Spanning Tree
    All-Pairs Shortest Paths
    Python 泰坦尼克生存率预测(修改)
    Python 分析Kaggle_Titanic案例
    Python 北京二手房成交数据分析过程
    数据挖掘主要解决的四类问题以及常用到的算法
  • 原文地址:https://www.cnblogs.com/smail-bao/p/8549557.html
Copyright © 2011-2022 走看看