Ansible下Inventory模块详解

前言

ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。

概念

Ansible可同时操作属于一个组的多台主机,组和主机之间的关系通过Inventory文件配置(vim /etc/ansible/ansible.cfg
)默认的文件路径为 /etc/ansible/hosts。

组成部分

例:
one.example.com
[tupb]
two.example.com
three.example.com
方括号[ ] 是组名,一个主机可以属于不同的组,比如一台服务器可以属于tupb组和tupb01组。这时可以指定tupb组和tupb02组,都可以操作这台主机。

ansible tupb -a ‘ls’
ansible tupb01 -a ‘ls’
ansible 192.168.1.2 -a ‘ls’

如何自定义链接端口
编辑host文件,在域名或者ip后,加上冒号和端口号
192.168.1.2:8080
one.example.com:8080

IP域名太长,起别名
jumper ansible_ssh_port=8080 ansible_ssh_host=192.168.1.2

不以root用户登录
jumper ansible_ssh_port=8080 ansible_ssh_host=192.168.1.2 ansible_ssh_user=tupb

机器太多,但是连续的,写起来比较麻烦
[tupb02]
tupb[1:20].example.com
tupb[a-h].example.com

Inventory 参数选项
ansible_ssh_host
ansible_ssh_prot
ansible_ssh_user
ansible_ssh_pass ssh 密码
ansible_sudo_pass sudo 密码
ansible_sudo_exe
ansible_connection 与主机的连接类型。eg:ssh;local;paramiko
ansible_ssh_pravate_key_file
ansible_shell_type 目标系统的shell类型
ansible_python_interpreter

分文件管理
分文件——例如
/etc/ansible/group_vars/tupb/install
/etc/ansible/group_vars/tupb/init
/etc/ansible/group_vars/tupb/foot

install 文件中的内容:
ntp_server:tupb.example.org
database_server:storage.example.org
这时候文件夹名就是组名。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值