ansible从入门到入土:带你从安装到实现“hello world“

如何安装?

别问,问就是无脑

 apt install -y ansible sshpass

如果是其他系统请自行更改管理器

基础配置

第一步:关闭key检查

命令如下:

sed -i 's/^#host_key_checking.*/host_key_checking = False/g' /etc/ansible/ansible.cfg
grep checking /etc/ansible/ansible.cfg

执行效果:

root@debian:~# sed -i 's/^#host_key_checking.*/host_key_checking = False/g' /etc/ansible/ansible.cfg
root@debian:~# grep checking /etc/ansible/ansible.cfg
# uncomment this to disable SSH key host checking
host_key_checking = False
# host key checking setting above.

也就是把host_key_checking设置为False

第二步:添加主机

/etc/ansible/hosts文件添加下面的内容(覆盖)

server1 ansible_ssh_host=10.1.0.3 ansible_ssh_port=22 ansible_ssh_pass=1
[hello]
server1

其中:

  • server1 服务器名称
  • ansible_ssh_host 服务器IP地址
  • ansible_ssh_port 端口
  • ansible_ssh_pass 密码

第三步:执行测试命令

实现hello world

ansible hello -m command -a 'echo hello world'

执行效果
在这里插入图片描述

ping检测

ansible hello -m ping

实现效果
在这里插入图片描述

启动服务

命令如下:

ansible hello -m command -a 'systemctl start httpd'

实现效果:
在这里插入图片描述

在这里插入图片描述
你学废了吗?

相关文章:

ansible从入门到入土:常用模块---->apt模块

ansible从入门到入土:教你如何编写ansible剧本实现yum安装软件

ansible从入门到入土:对剧本进行语法检查及真/伪执行剧本

ansible从入门到入土:带你从安装到实现“hello world

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

坐公交也用券

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值