zoukankan      html  css  js  c++  java
  • (2)ansible主机清单文件inventory

    1)inventory作用

    作用:通常用于定义要管理主机的认证信息,例如ssh登录用户名,密码等相关信息
    缺省文件:/etc/ansible/hosts

    2)定义主机组方式

    #vim /etc/ansible/hosts
    [webservers]
    192.168.1.31
    192.168.1.32
    
    [root@localhost ~]# ansible webservers -uroot -k -m ping -o
    SSH password: 
    192.168.1.32 | SUCCESS => {"changed": false, "ping": "pong"}
    192.168.1.31 | SUCCESS => {"changed": false, "ping": "pong"}
    

    3)批量定义主机

    #vim /etc/ansible/hosts
    [webservers]
    192.168.1.[31:34]
    
    [root@localhost ~]# ansible webservers -uroot -k -m ping -o
    SSH password: 
    192.168.1.32 | SUCCESS => {"changed": false, "ping": "pong"}
    192.168.1.31 | SUCCESS => {"changed": false, "ping": "pong"}
    

    4)内置参数:用户名和密码;命令行不用输入-u和-k选项

    #vim /etc/ansible/hosts
    [webservers]
    192.168.1.[31:32] ansible_ssh_user='root' ansible_ssh_pass='redhat'
    
    [root@localhost ~]# ansible webservers  -m ping -o
    SSH password: 
    192.168.1.32 | SUCCESS => {"changed": false, "ping": "pong"}
    192.168.1.31 | SUCCESS => {"changed": false, "ping": "pong"}
    

    5)内置参数:ssh端口

    #vim /etc/ansible/hosts
    [webservers]
    192.168.1.[31:32] ansible_ssh_user='root' ansible_ssh_pass='redhat' ansible_ssh_port='22'
    

    6)vars变量 :定义主机的内置参数

    #vim /etc/ansible/hosts
    [webservers]
    192.168.1.[31:32]
    [webservers:vars]
    ansible_ssh_user='root'
    ansible_ssh_pass='redhat'
    ansible_ssh_port='22'
    

    7)子组分类变量:children

    #vim /etc/ansible/hosts 
    [nginx]
    192.168.1.31
    [apache]
    192.168.1.32
    [webservers:children]
    apache
    nginx
    [webservers:vars]
    ansible_ssh_user='root'
    ansible_ssh_pass='redhat'
    ansible_ssh_port='22'
    
    [root@localhost ~]# ansible webservers -m ping -o
    192.168.1.31 | SUCCESS => {"changed": false, "ping": "pong"}
    192.168.1.32 | SUCCESS => {"changed": false, "ping": "pong"}
    [root@localhost ~]# ansible nginx -m ping -o
    192.168.1.31 | SUCCESS => {"changed": false, "ping": "pong"}
    [root@localhost ~]# ansible apache -m ping -o
    192.168.1.32 | SUCCESS => {"changed": false, "ping": "pong"}
    

    8)自定义主机清单文件

    [root@localhost ~]# ansible -i /etc/ansible/webservices webservers -m ping -o
    192.168.1.31 | SUCCESS => {"changed": false, "ping": "pong"}
    192.168.1.32 | SUCCESS => {"changed": false, "ping": "pong"}
    

    9)查看组中的主机列表

    [root@localhost ~]# ansible webservers --list-host
      hosts (2):
        192.168.1.32
        192.168.1.31
    [root@localhost ~]# ansible nginx  --list-host
      hosts (1):
        192.168.1.31
    
  • 相关阅读:
    开启chrome默认支持ipv6
    IC6151试用发现的问题
    锁存器(latch)、触发器(Flipflop)、寄存器(register)的区别
    文件管理小习惯:在特定位置创建快捷方式
    采用SPI接口的芯片
    阅读笔记:TI Grounding in mixedsignal systems demystified, Part 1
    IC6151使用小技巧,摸索中。。。
    基于RBAC模型的权限管理系统的设计和实现(转载)
    Cron 表达式说明
    组织结构及授权系统关系
  • 原文地址:https://www.cnblogs.com/lovelinux199075/p/9003789.html
Copyright © 2011-2022 走看看