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)信息的发送者和接收者如何维持 ...
随机推荐
- java程序运行时内存分配详解
java程序运行时内存分配详解 这篇文章主要介绍了java程序运行时内存分配详解 ,需要的朋友可以参考下 一. 基本概念 每运行一个java程序会产生一个java进程,每个java进程可能包含一个 ...
- centos7 安装配置rsyslog + LogAnalyzer + mysql
https://www.cnblogs.com/mchina/p/linux-centos-rsyslog-loganalyzer-mysql-log-server.html 安装LNMP 一键安装包 ...
- 黄聪:VPS服务器如何配置PHP.ini解决wordpress使用WP-Mail-SMTP插件发邮件出现Could not connect to SMTP host的解决办法
1.首先是WP-Mail-SMTP的下载地址:http://wordpress.org/plugins/wp-mail-smtp/ 2.出现Could not connect to SMTP host ...
- 关于android 动态设置view 样式 问题(默认style)
解决方案一: Button btn=new Button(new ContextThemeWrapper(mContext,R.style.service_text_dialog_style),nul ...
- WPF学习基础
1. d:DesignHeight="300" d:DesignWidth="200": 分别指的是在vs设计界面的宽高,Width="500&quo ...
- [转]JAVA 反射及使用
<%@page contentType="text/html; charset=GBK"%> <%@page import="java.security ...
- Traits
'folly/Traits.h' Implements traits complementary to those provided in <type_traits> Implements ...
- jquery选择器用法
jquery的基础选择器 选择器的用法其实跟咱们当时讲css的选择器用法类似,只是代码书写的不同 <ul> <li id="brother" class=&quo ...
- win10开启开发人员模式
工具: win10 方法如下: 1.在Windows10系统桌面,点击开始菜单,然后在弹出窗口中选择“设置”菜单项 2.在打开的设置窗口中,选择“更新和安全”图标,并点击打开更新和安全窗口 3.在打开 ...
- html链接路径
html链接的相对路径与绝对路径 绝对路径 完整的一个路径就是绝对路径,即包含schema://host[:port#]/path/.../[?query-string][#anchor] 例:htt ...