Ansible自动化运维

                       Ansible自动化运维

一.
1.生成密钥对、
[root@centos ~]# ssh-keygen -t RSA
在这里插入图片描述
2.上传密钥对
[root@centos ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.100.20
在这里插入图片描述
在这里插入图片描述
3.验证免交互式认证
在这里插入图片描述
4.修改yum配置文件
在这里插入图片描述
在这里插入图片描述
5.安装ansible
在这里插入图片描述
6.配置ansbile客户端
在这里插入图片描述
在这里插入图片描述
7.测试客户端连通性
[root@centos ~]# ansible -i /etc/ansible/hosts web -m ping
在这里插入图片描述
[root@centos ~]# ansible web -m ping
在这里插入图片描述
二、ansible的应用
1.ansible交互式管理
(1 )使用ansible交互式工具
[root@centos ~]# ansible-console
在这里插入图片描述
(2)切换组
在这里插入图片描述
(3)列出客户端
在这里插入图片描述
2.shell模组
(1)使用shell模组查看sshd
[root@centos ~]# ansible web -m shell -a ‘netstat -anptu | grep sshd’
在这里插入图片描述
(2)使用shell重定向操作
[root@centos ~]# ansible web -m shell -a ‘echo “centos02 192.168.100.20” >> /etc/hosts’
在这里插入图片描述
3.Command 模组
(1)使用Command 模组切换目录
[root@centos ~]# ansible web -m command -a ‘cd /mnt/’
在这里插入图片描述
4.copy 模组
(1)使用copy模组修改文件名字、权限、所属用户、和组
[root@centos ~]# ansible web -m copy -a ‘src=/etc/hosts dest=/root/host01 mode=777 owner=test group=root’
在这里插入图片描述

5.yum模块
(1)使用yum模块安装httpd
[root@centos ~]# ansible web -m yum -a ‘name=httpd state=present’
在这里插入图片描述
6.service
(1)使用service启动htppd服务
[root@centos ~]# ansible web -m service -a ‘name=httpd state=started’
在这里插入图片描述
7.User
(1)使用user创建用户
[root@centos ~]# ansible web -m user -a ‘name=bob system=yes shell=/bin/bash password=pwd@123’
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值