Centons7上安裝Ansible

1> Ansible是屬於Extra Packages for Enterprise Linux (EPEL)庫的一部分,因此要先安裝EPEL

[root@localhost ~]yum install epel-release

2> 直接安裝ansible,目前默認安裝的版本是2.2,官方持續在更新

[root@localhost ~]yum install ansible

3> 爲支持windows client,要安裝以下的包:安裝Python Winrm模塊

檢查有沒有安裝Python-pip包,直接執行:yum install python-pip

沒有python-pip包就執行命令 yum -y install epel-release
再次執行yum install python-pip
對安裝好的pip進行升級 pip install –upgrade pip

繼續安裝Winrm模塊:

sudo pip install http://github.com/diyan/pywinrm/archive/master.zip#egg=pywinrm

4> 底層通信基於PowerShell,管理機和遠程主機基於Kerbero認證,需額外安裝python-kerbero和MIT krb5依賴庫。

步驟1、 安裝python-kerberos依賴,命令如下:

yum -y install python-devel krb5-devel krb5-libs krb5-workstation

pip install Kerberos

安裝完成,檢查版本號:

ansible –version

打開etc/ansible/hosts文件

添加別名和指向的IP:自己取名(文件全部都是##註釋了的,自己添加清單,指要發佈的地方)
[webservers]
10.40.5.99
…..

繼續添加:client_host ansibly_ssh_user=root ansible_ssh_pass=password (password目標服務器的Root賬號的密碼)

後面爲配置項:

command:命令模塊,默認模塊,用於在遠程執行命令,不支持變量。ansible 192.168.139.128 -a ‘date’

cron:計劃任務模塊:ansible 192.168.139.128 -m cron -a ‘minute=”*/10” job=”/bin/echo “hell”” name=”test job” ‘

user:用戶管理模塊:ansible webservers -m user -a ‘name=”node1” ‘

ansible webservers -m copy -a ‘src=/etc/motd dest=/tmp/moth owner=root mode=640’

設置指定文件屬性:ansible webservers -m file -a ‘owner=mysql group=mysql mode=644 path=/etc/motd’

創建文件符號鏈接:ansible webservers -m file -a ’ path=/tmp/motd.link src=/etc/motd state=link’

Tower安裝:

參考博文,安裝過程無話可說,沒見這麼坑這麼矯情的軟件:http://www.linuxidc.com/Linux/2017-03/141422.htm

wget http://releases.ansible.com/ansible-tower/setup-bundle/ansible-tower-setup-bundle-3.0.2-1.el7.tar.gz

tar zxf ansible-tower-setup-bundle-3.0.2-1.el7.tar.gz
cd ansible-tower-setup-bundle-3.0.2-1.el7/

設置主機信息

sed -i “s#password=”#password=’admin’#g” inventory
sed -i “s#host=”#host=’10.40.4.195’#g” inventory
sed -i “s#port=”#port=’9090’#g” inventory

修改yum源

sed -i ‘s#dl.fedoraproject.org/pub#mirrors.ustc.edu.cn#g’ roles/packages_el/defaults/main.yml
sed -i ‘s/#baseurl=/baseurl=/g’ roles/packages_el/files/epel-7.repo
sed -i ‘s/mirrorlist=/#mirrorlist=/g’ roles/packages_el/files/epel-7.repo
sed -i ‘s#download.fedoraproject.org/pub#mirrors.ustc.edu.cn#g’ roles/packages_el/files/epel-7.repo

yum -y install centos-release-scl-rh centos-release-scl
sed -i ‘s#mirror.centos.org#centos.ustc.edu.cn#g’ /etc/yum.repos.d/CentOS-SCLo-scl.repo
sed -i ‘s#mirror.centos.org#centos.ustc.edu.cn#g’ /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
yum -y install supervisor

yum install \ http://download.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

使用方法:http://www.178linux.com/14860

發佈了24 篇原創文章 · 獲贊 2 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章