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

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