在CentOS下安裝Ansible非常的簡單,但需要注意一下幾點:
1、為了簡單建議使用yum的epel源安裝,畢竟沒什么模塊需要自己定制的,如果非要指定版本,可以指定不同的版本,下面會講。
2、母機記得創建秘鑰,以及被控制的機做免密登錄認證,Ansible核心是免密登錄。
3、高手級別的使用應該是playbooks,但基本入門使用基本的命令行也夠了,這里先不講解playbooks,並且Ansible還有非常多的功能模塊可以深入。
下面是安裝步驟:
1、源碼安裝:
# 安裝epel源,為了安裝pip yum install -y epel-release # 下載源碼 git clone git://github.com/ansible/ansible.git --recursive
# 下載自定義版本源碼(可選)
# wget https://github.com/ansible/ansible/archive/v2.6.8.tar.gz
# tar -zxvf v2.6.8.tar.gz cd ./ansible # 安裝pip yum install -y python-pip pip install -r ./requirements.txt # 安裝 python setup.py install # 遷移目錄 mkdir -p /data/service/ansible ln -s /data/service/ansible /etc/ansible echo "127.0.0.1" > /data/service/ansible/hosts # 后續更新 # git pull --rebase # git submodule update --init --recursive
源碼編譯安裝有個好處,可以自定義源碼版本。
2、yum源安裝
# 安裝依賴 yum install -y epel-release # 安裝ansible yum install -y ansible # 遷移目錄 mkdir -p /data/service/ansible rsync -av /etc/ansible /data/service/ mv /etc/ansible{,_bak} ln -s /data/service/ansible /etc/ansible
yum安裝可能不是最新版本,並且不能選擇版本。
一鍵安裝腳本:
https://github.com/easonjim/centos-shell/blob/master/ansible/install-ansible-last.sh
參考:
https://ansible-tran.readthedocs.io/en/latest/docs/intro_installation.html
https://www.cnblogs.com/Eivll0m/p/4762704.html
