Ansible 环境搭建 概述 安装依赖 安装 pip 安装 Ansible 配置 Ansible

概述

官网提供了不同环境的安装方式,可以根据自己的具体情况,选择不同安装方式。鉴于 Ansible 是通过 python 开放的,可直接通过 pip 来安装。

安装依赖

检查环境依赖,如果没有则需要安装,不然在安装 Ansible 时会报错。

$ yum -y install gcc python-devel openssl-devel

安装 pip

检查下环境是否已安装有 pip,如果没有,可通过如下方式安装。

$ sudo easy_install pip

若出现 “easy_install: command not fount”,可通过如下方式安装:

$ wget https://bootstrap.pypa.io/ez_setup.py -O - | python

安装 Ansible

sudo pip install ansible

配置 Ansible

Ansible 的一些的设置可以通过配置文件完成。在大多数场景下默认的配置就能满足大多数用户的需求,在一些特殊场景下,用户还是需要自行修改这些配置文件。如果安装过程中没有 ansible.cfg 文件,可以自己创建。
系统读取配置文件的顺序:

* ANSIBLE_CONFIG (an environment variable)
* ansible.cfg (in the current directory)
* .ansible.cfg (in the home directory)
* /etc/ansible/ansible.cfg

版本 1.5 之前的读取顺序如下:

* ansible.cfg (in the current directory)
* ANSIBLE_CONFIG (an environment variable)
* .ansible.cfg (in the home directory)
* /etc/ansible/ansible.cfg

创建配置文件。

mkdir -p /etc/ansible
vi /etc/ansible/ansible.cfg

最新配置文件:https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg

根据需要,可以调整参数。
参考如下:

host_key_checking = false
inventory = /opt/ansible/hosts
sudo_user = root
remote_port = 22
roles_path = /opt/ansible/roles
timeout = 10
remote_user = root
log_path = /var/log/ansible.log

参考地址:
ansible安装:http://docs.ansible.com/ansible/latest/intro_installation.html
ansible配置:http://docs.ansible.com/ansible/latest/intro_configuration.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章