一、安裝Ansible 步驟
1、命令行查看Python
#Python --vesion
python 版本需要是2.4以上版本(Python 3.0是不同語言)
2、centos7 用戶需先配置 EPEL
#yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# install the epel-release RPM if needed on CentOS, RHEL, or Scientific Linux
$ sudo yum install ansible
安裝前確認安裝好了rpm-build,make,python2-devel
#yum install rpm-build
#yum install make
#yum python2-devel
3、源碼下載安裝
#git clone git://github.com/ansible/ansible.git
#cd ./ansible
#make rpm
#sudo rpm -Uvh ~/rpmbuild/ansible-*.noarch.rpm
4、配置文件
兩個核心文件:ansible.cfg和hosts文件,默認都存放在/etc/ansible目錄下。
ansible.cfg:主要設置一些ansible初始化的信息,比如日志存放路徑、模塊、插件等配置信息
hosts:機器清單,進行分組管理
拷貝配置文件至指定目錄
mkdir /etc/ansible
cp -r examples/* /etc/ansible/
二、centos 7 下安裝ansible遇見的問題
1、centos中執行apt-get命令提示apt-get command not found
在centos下應該用yum install xxx
yum和apt-get的區別
一般來說著名的linux系統基本上分兩大類:
1.RedHat系列:Redhat、Centos、Fedora等
2.Debian系列:Debian、Ubuntu等
RedHat 系列
1 常見的安裝包格式 rpm包,安裝rpm包的命令是“rpm -參數”
2 包管理工具 yum
3 支持tar包
Debian系列
1 常見的安裝包格式 deb包,安裝deb包的命令是“dpkg -參數”
2 包管理工具 apt-get
3 支持tar包
2、從源碼安裝Ansible時提示
輸入#git clone git://github.com/ansible/ansible.git --recursive
提示:command not found
出錯原因:服務器沒有安裝GIT,所以導致出錯
解決方法:
Centos下使用:yum install git -y 或者 yum install -y git
Ubuntu/Debian下使用 : apt-get install git -y
3、輸入make rmp 是提示 :ImportError: No module named packaging.version
解決方法:pip install packaging
4、輸入pip install packaging 提示Could not find a version......
解決方法:
輸入命令:pip install packaging --ignore-install
輸入提示命令:pip install --upgrade pip
參考鏈接:
https://blog.51cto.com/lixcto/1431247
https://blog.csdn.net/learner198461/article/details/83444187
https://www.cnblogs.com/LuisYang/p/5960660.html
https://www.cnblogs.com/xulingjie/p/10476359.html