Ansible 笔记 (1) - 安装和配置
本文参考 《Ansible 自动化运维和最佳实践》,这两天刚读这本书,写写总结。主控机环境是 centos 7,被控机均是 centos 6.8 。
确保 python 版本大于 2.6
[root@localhost ~]# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
1、源码安装
可以从 github 下载源码后安装
cd /data1
git clone git://github.com/ansible/ansible.git --recursive
cd ./ansible
easy_install pip
yum -y install gcc gcc-c++ autoconf
pip install paramiko PyYAML Jinja2 httplib2 six
source ./hacking/env-setup
如果 github更新版本则需要更新 git 源码树和 git 中的 submodules,该模块是指向 Ansible 自身的模块
重启系统后可能会发现 ansible 命令出问题,这时候需要再次 source,暂时不知道怎么解决,推荐大家使用 yum 源安装。
2、yum 源安装 (推荐)
以下是 EPEL 的浙江大学 yum 源地址,经常更新,如果找不到则直接往上级目录找
- RHEL(centos 5)
rpm -Uvh http://mirrors.zju.edu.cn/epel/5/x86_64/epel-release-5-4.noarch.rpm
- RHEL(centos 6)
rpm -Uvh http://mirrors.zju.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm
- RHEL(centos 7)
rpm -Uvh http://mirrors.zju.edu.cn/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
# yum clean all
# yum update -y
yum install ansible -y
yum 源更新一般会比较久,请耐心等待,如果不更新可能会遇到其他问题。
如果 rpm 安装错了,例如 centos6 安装了 centos7 的 yum 源, 则会出现 Error: xz compression not available 的错误,需要先卸载
yum remove epel-release
rm -rf /var/cache/yum/x86_64/6/epel/
然后重新执行正确命令
yum 源安装可能会导致 ansible 安装的路径是在 python2.6 下,如果是这种情况则可以将 python2.6/site-packages/ 中的 ansible 和 ansible-2.2.1.0-py2.6.egg-info/ 复制到 python2.7/site-packages/ 目录下,并修改 /usr/bin/ansible* 的 python 路径为 2.7,删掉 2.6 下的原来目录即可
3、验证版本
[root@localhost ansible]# ansible --version
ansible 2.3.0 (devel 72c96b3ac3) last updated 2017/03/04 12:07:12 (GMT +800)
config file =
configured module search path = Default w/o overrides
python version = 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
4、配置文件 ansible.cfg
如果通过 yum 安装或者 pip 安装,那么 ansible.cfg 存放在 /etc/ansible 目录下,如果通过 github 安装则在仓库中的 examples 目录下找到 ansible.cfg 然后拷贝到 /etc/ansible 目录下即可
[defaults] # some basic default values... inventory = /etc/ansible/hosts
library = /usr/share/my_modules/
module_utils = /usr/share/my_module_utils/
remote_tmp = ~/.ansible/tmp
local_tmp = ~/.ansible/tmp
forks = 5
poll_interval = 15
sudo_user = root
#ask_sudo_pass = True
#ask_pass = True
transport = smart
remote_port = 22
module_lang = C
module_set_locale = False
log_path = /var/log/ansible.log
host_key_checking = True
[root@localhost examples]# ansible --version
ansible 2.3.0 (devel 72c96b3ac3) last updated 2017/03/04 12:07:12 (GMT +800)
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/usr/share/my_modules/']
python version = 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
这时候发现 config file 已经有值了
5、配置 inventory
在步骤 [4] 中已经配置了 inventory = /etc/ansible/hosts,所以在主控机编写配置如下
[root@localhost ~]# vim /etc/ansible/hosts
[webserver]
192.168.34.129
192.168.34.130
6、配置 linux 主机 ssh 无密码访问
如果每台被控机密码都一样则没必要完成这一步,可以在命令行上增加 -k password 参数。
首先生成密钥对,然后将 id_rsa.pub 使用 ssh-copy-id 发送到所有的被控机即可。
ssh-keygen
/usr/bin/ssh-copy-id [-h|-?|-n] [-i [identity_file]] [-p port] [[-o <ssh -o options>] ...] [user@]hostname
[root@localhost ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.34.129
The authenticity of host '192.168.34.129 (192.168.34.129)' can't be established.
RSA key fingerprint is 0e:a7:fc:55:fe:91:fa:e8:c5:b6:44:f2:d0:08:a1:8f.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.34.129's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'root@192.168.34.129'"
and check to make sure that only the key(s) you wanted were added.
Ansible 笔记 (1) - 安装和配置的更多相关文章
- mysql笔记1—安装、配置和基础的数据表操作
本篇笔记主要分为两部分: 1,安装完毕之后的简单配置 2,数据的类型.简单的数据表操作命令 一.mysql安装完毕之后 windows和linux环境,除mysql的安装.配置有所不同,其他操作一样, ...
- ansible介绍、安装与配置
一.ansible简介 (1)简介: Ansible是近年越来越火的一款自动化运维工具,其主要的功能是帮助运维实现IT工作的自动化,降低人为操作失误.提高业务自动化率,常用于软件部署.配置自动化.管理 ...
- Vue学习笔记-VSCode安装与配置
一 使用环境: windows 7 64位操作系统 二 VSCode安装与配置 1.下载: https://code.visualstudio.com 直接点击即可. 2. 点击按装程序,默认安 ...
- docker学习笔记1 -- 安装和配置
技术资料 docker中文官网:http://www.docker.org.cn/ 中文入门课程:http://www.docker.org.cn/book/docker.html docker学习笔 ...
- Ansible 入门 (1) - 安装和配置
本文参考 <Ansible 自动化运维和最佳实践>,这两天刚读这本书,写写总结.主控机环境是 centos 7,被控机均是 centos 6.8 . 确保 python 版本大于 2.6 ...
- ansible之一:安装与配置
ansible特点: 1.不需要安装客户端,通过sshd去通信 2.基于模块工作,模块可以由任何语言开发 3.不仅支持命令行试用模块,也支持yaml格式得playbook 4.支持sudo 5.有提供 ...
- MongoDB学习笔记——数据库安装及配置
MongoDB数据库安装 MongoDB官方下载地址:https://www.mongodb.com/download-center 首先需要根据Windows版本选择正确的MongoDB版本进行安装 ...
- cakephp2.7的学习笔记1 —— 安装与配置
CakePHP2.7的安装 下载 https://github.com/cakephp/cakephp/releases 解压后扔进你的www目录就可以直接访问 按照提示,修改这两项配置,替换成你喜欢 ...
- rabbitmq实践笔记(一):安装、配置与使用初探
引言: 对于一个大型的软件系统来说,会有很多的组件.模块及不同的子系统一起协同工作,模块之间的通信需要一个可靠的通信管道来保证 ,通信管道需要解决解决很多问题,比如: 1)信息的发送者和接收者如何维持 ...
随机推荐
- 微信后端服务架构及其过载控制系统DAGOR
微信架构介绍 眼下的微信后端包含3000多个移动服务,包括即时消息.社交网络.移动支付和第三方授权.该平台每天收到的外部请求在10 ^10个至10^11个.每个这样的请求都会触发多得多的内部微服务 ...
- js setInterval每隔一段时间执行一次
js setInterval每隔一段时间执行一次setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式.setInterval() 方法会不停地调用函数,直到 clearI ...
- debian下为apache启用rewrite模块
如果我们是自己编译的apache,那么启用或禁用某个模块应该说是比较容易的事,只要修改apache的配置文件就可以了.但是我们没有理由不用已经做好的二进制文件进行安装,使用apt-get要方便多了. ...
- GCC参数详解 二
1简介 2简单编译 2.1预处理 2.2编译为汇编代码(Compilation) 2.3汇编(Assembly) 2.4连接(Linking) 3多个程序文件的编译 4检错 5库文件连接 5.1编译成 ...
- 华为5573+联通4G上网SIM+ROS hap ac-RB962UiGS-5HacT2HnT 上网
华为5573+联通4G上网SIM+ROS hap ac-RB962UiGS-5HacT2HnT 上网 原理其实是这样的,ROS的USB口连接华为5573: 华为5573看成是一个路由器,他的外网网卡走 ...
- word2vec相关
word '\xe8\xb6\x85\xe8\x87\xaa\xe7\x84\xb6\xe7\x8e\xb0\xe8\xb1\xa1' not in vocabulary 分词后的样本格式:英雄联盟, ...
- fiddler工具条、状态栏、请求信息栏各按钮的作用
1.fiddler工具条 2.fiddler状态栏 3.请求信息栏
- C#串口编程测试收发
原文:http://www.cnblogs.com/vsdot/archive/2013/04/23/3263348.html 基本传递方法:RS232传输要有1位起始位,8位数据位.1位校验位( ...
- 纯C++binder服务和客户端实例
继承关系: 文件关系 IHelloService.h /* 参考: frameworks\av\include\media\IMediaPlayerService.h */ #ifndef ANDRO ...
- 迷你MVVM框架 avalonjs 1.3.4发布
发现一个以前从来没发现的大BUG,紧急发布此版本. fix getEachProxy BUG,此BUG会导致监控数组在删除某元素然后再添加元素时出现问题. avalon ms-on-*绑定添加一个钩子 ...