ansible安装及基础应用

一、ansible安装

1.源码包安装

# 下载安装
git clone git://github.com/ansible/ansible.git --recursive
# 依赖
pip install paramiko PyYAML Jinja2 httplib2 six
cd ./ansible
source ./hacking/env-setup
# 如果开启了selinux,需要安装libselinux-python以获取template相关函数支持
# 升级
git pull --rebase
git submodule update --init --recursive

2.可以自己制作RPM、DEB包

git clone git://github.com/ansible/ansible.git --recursive
cd ./ansible
make rpm;make deb

3.包管理器安装

# ubuntu
sudo apt-get install ansible
# centos,redhat,fedora
sudo yum install ansible
# Gentoo
emerge -av app-admin/ansible
# FreeBSD
sudo pkg install ansible   #或者下一行
sudo make -C /usr/ports/sysutils/ansible install

4.pip

sudo pip install ansible

二、 inventory配置

主机清单/etc/ansible/hosts文件配置示例
# 域名
www.fsrmblog.com.cn 
www.fsrmblog.com.cn:444# ssh端口非默认值
# ip地址
10.1.1.10
# 本地 连接类型(可不加)
localhost ansible_connection=local
# 别名
jokename ansible_ssh_port=11111 ansible_ssh_host=10.10.10.10
# 范围简写
www.spider[a:z][1:9].com.cn
# 主机分组
[webserver1]
host1 ansible_connection=ssh ansible_ssh_user=guest
[webserver2]
# 主机组作为其他组子成员
webserver1
# 主机变量
host2 http_port=303 maxRequestsPerChild=909
# 组变量
[webserver2:vars]
ntp_server=ntp.atlanta.example.com
proxy=proxy.atlanta.example.com
可以分文件定义Host和Group变量,但其必须遵循YAML语法
inventory参数
# 将要连接的远程主机名.与你想要设定的主机的别名不同的话,可通过此变量设置.
ansible_ssh_host
# ssh端口号.如果不是默认的端口号,通过此变量设置.
ansible_ssh_port
# 默认的 ssh 用户名  
ansible_ssh_user
# ssh 密码 
ansible_ssh_pass
# sudo 密码
ansible_sudo_pass
# sudo 命令路径(适用于1.8及以上版本)
ansible_sudo_exe (new in version 1.8)
# 与主机的连接类型.比如:local, ssh 
ansible_connection
# ssh 使用的私钥文件.适用于有多个密钥,而你不想使用 SSH 代理的情况.
ansible_ssh_private_key_file
# 目标系统的shell类型
ansible_shell_type
# 目标主机的 python 路径.
ansible_python_interpreter
动态inventory

inventory可以通过LDAP(Lightweight Directory Access Protocol,轻量级目录访问协议)、Cobbler、CMDB以及与服务提供商的管理工具进行外部导入

四、ansible基本命令格式

ansible <pattern_goes_here> -m <module_name> -a <arguments>
# 示例
ansible all -m ping

未完待续,编辑中emmm

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值