ansible初步

Purpose

  • 了解ansible能做什么
  • 了解ansible部署环境
  • 安装ansible管理主机

Reference

Resolution

why ansible?

引用ansible在github上的介绍:

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications— automate in a language that approaches plain English, using SSH, with no agents to install on remote systems.

简单说就是运维自动化,减少重复部署,使用SSH协议,且无需安装客户端。

要说缺点嘛,管理主机不能是Windows,Nagios也是==。

Install

  • Python2.6以上
  • Linux/Unix各发行版

安装过程略。

python模块

本机环境

  • Ubuntu 16.04.3 LTS (GNU/Linux 4.10.0-28-generic x86_64)
  • Python 2.7.12
  • OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g 1 Mar 2016
  • ansible 2.0.0.2

ansible连接远程主机原理

默认会在本地的 OpenSSH可用时会尝试用其进行远程通讯.这会启用ControlPersist(一个性能特性,SSH_5.6以上支持),Kerberos,和在~/.ssh/config中的配置选项如 Jump Host setup.然而,当你使用Linux企业版6作为主控机(红帽企业版及其衍生版如CentOS),其OpenSSH版本可能过于老旧无法支持ControlPersist. 在这些操作系统中,Ansible将会退回并采用 paramiko (由Python实现的高质量OpenSSH库). 如果你希望能够使用像是Kerberized SSH之类的特性,烦请考虑使用Fedora, OS X, 或 Ubuntu 作为你的主控机直到相关平台上有更新版本的OpenSSH可供使用,或者启用Ansible的“accelerated mode”.

添加受控主机

将管理主机公钥添加到受控主机的.ssh/authorized_keys文件中。

最快的方法是使用ssh_copy_id命令。

添加好测试一下。

然后编辑/etc/ansible/hosts文件,将受控主机IP地址添加到文件中。

执行ansible all -m ping,如返回SUCCESS则成功,如其他,则可使用-vvvv参数输出详细log,排错。

© 2019 lvbin's Blog All Rights Reserved.
Theme by hiero