zoukankan      html  css  js  c++  java
  • Ansible inventory(主机清单的静态文件)

    Ansible inventory(主机清单的静态文件)

    刚开始的时候大概说了一下 inventory 是存放主机地址的一个文件。现在我们详细介绍它:

    定义主机和组:
    [ansible:children]     #定义了一个ansible的组,下面包括了sunq 和 test的组
    sunq
    test

    [sunq]
    192.168.137.101

    [test]
    192.168.137.102

    [test:vars]
    ansible_ssh_port=22     #针对test组使用inventory内置变量,定义了ssh端口

    还可以将这个inventory 文件放在其他的地方:

    新建一个docker的主机inventory

    vim  /root/ansible/docker
    写入以下文件
    [docker]
    192.168.137.102

    执行时候 加上 -i 调用这个文件:
    [root@localhost ansible]# ansible -i /root/ansible/docker all -m command -a 'uptime'
    192.168.137.102 | SUCCESS | rc=0 >>
    15:39:05 up 1:24, 2 users, load average: 0.00, 0.01, 0.05

    还可以支持多个inventory列表:

    例如 在刚才的目录下 再新增多一个inventory文件

    vim /root/ansible/test

    写入内容:

    [test] 192.168.137.101

    先看一下ansible 的目录结构:

    [root@localhost ~]# tree ansible/
    ansible/
    ├── docker
    └── test

    0 directories, 2 files

    执行:

    [root@localhost ~]# ansible -i /root/ansible/ all -m command -a 'uptime'
    192.168.137.102 | SUCCESS | rc=0 >>
    15:46:36 up  1:32,  2 users, load average: 0.00, 0.01, 0.05

    192.168.137.101 | SUCCESS | rc=0 >>
    15:46:58 up  1:32,  4 users, load average: 0.04, 0.04, 0.05

     

    inventory内置参数:
    ansible_ssh_host # 要连接的主机名
    ansible_ssh_port # 端口号默认是22
    ansible_ssh_user # ssh连接时默认使用的用户名
    ansible_ssh_pass # ssh连接时的密码
    ansible_sudo_pass # 使用sudo连接用户是的密码
    ansible_ssh_private_key_file # 秘钥文件如果不想使用ssh-agent管理时可以使用此选项
    ansible_shell_type # shell的类型默认sh
    ansible_connection # SSH 连接的类型: local , ssh , paramiko在 ansible 1.2 之前默认是 paramiko ,后来智能选择,优先使用基于 ControlPersist 的 ssh (支持的前提)
    ansible_python _ interpreter #用来指定 python 解释器的路径,同样可以指定ruby 、perl 的路径

     

  • 相关阅读:
    linux Segmentation faults 段错误详解
    linux cut
    linux sed
    linux tr
    linux ar
    objdump--反汇编查看
    linux中dd命令
    readelf
    登录后,前端做了哪些工作,如何得知已登录?
    正向代理和反向代理?
  • 原文地址:https://www.cnblogs.com/zyos/p/10189353.html
Copyright © 2011-2022 走看看