1 Star 0 Fork 0

Jack / ansible

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

ansible

项目介绍:

实现目的:使用 Ansibe playbook 检查 web 服务器状态,模拟 httpd 没有启动,启动 httpd,使得 web 服务器恢复正常。

文件说明:

1、pre.yml:安装 httpd 服务,配置 httpd 服务

2、fix_web.yml:检测出 httpd 服务出现问题,并启动 httpd 服务,使得 web 服务器恢复正常。

环境说明:

系统:el7

主机名:web

IP:192.168.149.6

Ansible控制节点和被管节点均为web服务器

[root@web ~]# uname -a

Linux web 3.10.0-1160.36.2.el7.x86_64 #1 SMP x86_64 x86_64 x86_64 GNU/Linux

[root@web ~]# hostname

web

[root@web ~]# ip a|grep inet

inet 192.168.149.6/24 brd 192.168.149.255 scope global ens33

[root@servera ~]# ansible web -m ping -o

192.168.149.6 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "ping": "pong"}

实验过程:

[root@web ~]# ansible-playbook pre.yml

[root@web ~]# curl web

web server is running by @iamjacker

[root@web ~]# #模拟 httpd 没有启动

[root@web ~]# systemctl stop httpd

[root@web ~]# ansible-playbook fix_web.yml

PLAY [web] **********************************************************************************************************************

TASK [Check that a page returns a status 200 and fix if the word jack is not in the page contents] ****************************** fatal: [192.168.149.6]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "content": "", "elapsed": 0, "msg": "Status code was -1 and not [200]: Request failed: <urlopen error [Errno 111] Connection refused>", "redirected": false, "status": -1, "url": "http://192.168.149.6"} ...ignoring

TASK [debug] ******************************************************************************************************************** ok: [192.168.149.6] => { "res": { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "content": "", "elapsed": 0, "failed": true, "msg": "Status code was -1 and not [200]: Request failed: <urlopen error [Errno 111] Connection refused>", "redirected": false, "status": -1, "url": "http://192.168.149.6" } }

TASK [debug] ******************************************************************************************************************** ok: [192.168.149.6] => { "msg": "Status code was -1 and not [200]" }

TASK [start web service if web service is not started] ************************************************************************** changed: [192.168.149.6]

PLAY RECAP ********************************************************************************************************************** 192.168.149.6 : ok=4 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=1

实验验证:web 服务器恢复正常

[root@web ~]# curl web

web server is running by @iamjacker

MIT License Copyright (c) 2021 Jack Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

ansible示例,希望给大家带来些启发@iamjacker 展开 收起
YAML
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
YAML
1
https://gitee.com/iamjack/ansible.git
git@gitee.com:iamjack/ansible.git
iamjack
ansible
ansible
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891