zoukankan      html  css  js  c++  java
  • ansible主机组配置及秘钥分发

    ansible主机组配置及秘钥分发

    ansible主机组文件位于/etc/ansible/hosts文件中

     1 hosts主机经常使用到的变量为:
     2 ansible_ssh_host     #用于指定被管理的主机的真实IP
     3 ansible_ssh_port     #用于指定连接到被管理主机的ssh端口号,默认是22
     4 ansible_ssh_user     #ssh连接时默认使用的用户名
     5 ansible_ssh_pass     #ssh连接时的密码
     6 ansible_sudo_pass    #使用sudo连接用户时的密码
     7 ansible_sudo_exec    #如果sudo命令不在默认路径,需要指定sudo命令路径
     8 ansible_ssh_private_key_file     #秘钥文件路径,秘钥文件如果不想使用ssh-agent管理时可以使用此选项
     9 ansible_shell_type     #目标系统的shell的类型,默认sh
    10 ansible_connection     #SSH 连接的类型: local , ssh , paramiko,在 ansible 1.2 之前默认是 paramiko ,后来智能选择,优先使用基于 ControlPersist 的 ssh (支持的前提)
    11 ansible_python_interpreter     #用来指定python解释器的路径,默认为/usr/bin/python 同样可以指定ruby 、perl 的路径
    12 ansible_*_interpreter     #其他解释器路径,用法与ansible_python_interpreter类似,这里"*"可以是ruby或才perl等其他语言

    示例:[clu] 自定义组名192.168.1.2 ip(可写主机名及实际ip)

    [clu]            (自定义组名)
    192.168.1.2 (自定义主机或ip)
    192.168
    .1.3:222 (ip后:等于实际端口号) [webservers] node[01:50] .example.com (使用[01:50]等格式可指定范围主机) [clu] 182.92.167.214:12214 ansible_ssh_user='root' ansible_ssh_pass='mO88vynZ3Y' 123.56.82.56:12356 ansible_ssh_user='root' ansible_ssh_pass='DmmPS' (也可以写成这样的) 如密码相同批量主机可定义共同变量 [clu] 192.168.1.2 192.168.1.3 [clu:vars]
    ansible_ssh_user
    ='root' ansible_ssh_pass='12345678'

    多主机组管理
    [tol:children]
    clu
    webservers

    秘钥分发:

    centos中生成秘钥
    1. ssh-keygen -t rsa(生成秘钥命令,秘钥路径/root/.ssh/id_ras.pub)
    2.配置hosts主机组,将ip进行及端口 密码进行填写
    3. ansible c7 -m  authorized_key  -a "user=root key='{{ lookup('file', '/root/.ssh/id_rsa.pub') }}'"
    (使用ansible anthorized_key模块将生成秘钥进行下发)
    4.删除ansible hosts中有关密码部分
  • 相关阅读:
    BestCoder Round #65 hdu5590(水题)
    codeforces Ebony and Ivory(水题)
    codeforces 630B Moore's Law
    BestCoder Round #69 (div.2)(hdu5611)
    BestCoder Round #73 (div.2)(hdu 5630)
    codeforces 630A Again Twenty Five!
    codeforces 630C Lucky Numbers
    codeforces 630D Hexagons!
    Codeforces243C-Colorado Potato Beetle(离散化+bfs)
    hdu4453-Looploop(伸展树)
  • 原文地址:https://www.cnblogs.com/dahuige/p/13902546.html
Copyright © 2011-2022 走看看