1. 在/etc/ansbile/hosts中添加主機init
2. 在sysinit.yml中修改要初始化的機器:
hosts: init
3. 設置不檢查key
export ANSIBLE_HOST_KEY_CHECKING=False
4. 由於開啓了selinux,因此須要安裝libselinux-python
ansible init -m shell -a 'yum install libselinux-python -y' -k
5. 執行初始化
ansible-playbook sysinit.yml -k
6. 複製key到主機
ssh-copy-id -i "/root/.ssh/id_rsa.pub" "-p 50000 lsyw@162.221.12.108"
7. 測試key通訊
####從新在hosts中編輯一個組nginx,而後配置group_vars:
ansible_user: lsyw
ansible_port: 50000
ansible_su_password: "0xxxxx"
ansible nginx -m ping
8. 安裝nginx
在tengine_comm_deploy.yml中修改hosts爲nginx
執行命令:ansible-playbook tengine_comm_deploy.yml -S
9. 部署d9導航頁
cd /root/distri #切換到ansible源代碼存放目錄
rz -y #上傳源代碼到ansible主機
ansible nginx -S -R root -m unarchive -a "src=d9_201608311030.zip dest=/data"
ansible nginx -S -R root -m shell -a "ln -s /data/d9_201608311030 /data/www"
更新nginx配置文件:
ansible nginx -S -R root -m shell -a "rm -rf /usr/local/gacp/nginx/conf/vhosts.d/*"
ansible nginx -S -R root -m copy -a "src=www.d9.com.conf dest=/usr/local/gacp/nginx/conf/vhosts.d/"
ansible nginx -S -R root -m shell -a "/sbin/service nginx reload"
ansible nginx -S -R root -m shell -a "netstat -nl "
10. 添加防火牆
ansible nginx -S -R root -m shell -a "/sbin/iptables -I INPUT 5 -p tcp --dport 80 -m state --state NEW -j ACCEPT"
ansible nginx -S -R root -m shell -a "/sbin/service iptables save"python