linux 运维自动化之ansible,使用ansible的playbook实现自动化安装httpd
1、环境搭建
1.自动化管理机 192.168.170.7 自动化管理极ansible 被管理节点以下三台 192.168.170.6 192.168.170.17 192.168.170.37
1. yum install ansible -y #装包 2.rpm -ql ansible | more #查看主要文件 3.vim /etc/ansible/hosts #配置主机清单 [wbs] 192.168.170.6 192.168.170.17 [apps] 192.168.170.37 [dbs] 192.168.170.6 4.ssh-keygen 实现基于sshkey验证管理 ssh-copy-id 192.168.170.6 ssh-copy-id 192.168.170.17 ssh-copy-id 192.168.170.37 5、 vim /etc/ansible/ansible.cfg #修改配置文件 一般保持默认 #host_key_checking= False # 检查对应服务器的host_key,建议取消注释 6、配置完毕我们用ping模块测试下链接情况 [root@chujiapeng ~]# ansible all -m ping 192.168.170.37 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" } 192.168.170.6 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" } 192.168.170.17 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" }
2.使用ansible的playbook实现自动化安装httpd
1.#ansible 机器上准备httpd的配置文件 1、mkdir /data/playbook 2、cd /data/playbook 3、yum install httpd -y 4.cp /etc/httpd/conf/httpd.conf .
准备脚本
vim httpd.yml
--- - hosts: wbs remote_user: root tasks: - name: install yum: name=httpd - name: config copy: src=/data/playbook/httpd.conf dest=/etc/httpd/conf/ notify: restart httpd - name: service service: name=httpd state=started enabled=yes handlers: - name: restart httpd service: name=httpd state=restarted
3.测试
把配置文件的端口改成9527
执行自动化部署脚本
检查远程主机是否启动,我们看到 两台主机服务已经起来
测试成功
jiapengchu
posted on 2020-12-19 10:34 jiapengchu 阅读(113) 评论(0) 编辑 收藏 举报