ansible搭建使用

Ansible自动化工具的使用
一.Ansible的安装
1、系统环境
系统平台: CentOS 7
Ansible Server: 192.168.96.128
Ansible Client: 192.168.96.131
(1)写hosts记录
[root@Ansible ~]# echo “192.168.96.128 Ansible” >> /etc/hosts
[root@Ansible ~]# echo “192.168.96,131 Client” >> /etc/hosts
(2)关闭firewalld和selinux
[root@Ansible ~]# systemctl stop firewalld && systemctl disable firewalld
(3)关闭selinux
[root@Ansible ~]# setenforce 0
[root@Ansible ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config
2、yum源安装
(1)配置好epel yum源安装相应的基础模块,可以使用yum直接安装
[root@Ansible ~]# yum -y install python PyYAML python-paramiko python-jinja2 python-simplejson
在这里插入图片描述
(2)安装Ansible
[root@Ansible ~]# yum -y install ansible
l
在这里插入图片描述
三、Ansible的配置
1、Ansible配置
注:centos7.0安装Ansible后发现找不到ansible.cfg,配置文件的路径如下图,并将配置文件拷贝过去

[root@Ansible ansible-2.5.0]# cd examples/
[root@Ansible examples]# pwd --注意路径
/usr/src/ansible-2.5.0/examples
[root@Ansible examples]# ls
ansible.cfg hosts
[root@Ansible examples]# mkdir /etc/ansible --创建ansible目录
[root@Ansible examples]# cp ansible.cfg hosts /etc/ansible/ --拷贝文件
[root@Ansible examples]# ls -l /etc/ansible/
总用量 24
-rw-r–r-- 1 root root 19315 4月 17 14:25 ansible.cfg
-rw-r–r-- 1 root root 1016 4月 17 14:25 hosts
2、配置ssh免密登录(只在控制端使用)
[root@Ansible ~]# ssh-keygen -t rsa --直接回车即可,不用设置密钥密码。
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
bc:4e:4e:5f:61:a3:37:08:b0:c4:00:98:90:5b:c6:9f root@Ansible.01.com
The key’s randomart image is:
±-[ RSA 2048]----+
|o=… |
|+ + o |
| + . .+ |
|. E. + |
| . S + |
| o + o |
| + o + |
| = . o . |
| o . |
±----------------+

[root@Ansible ~]# cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
[root@Ansible ~]# chmod 600 /root/.ssh/authorized_keys
将公钥传给被管理的机器节点
[root@Ansible ~]# scp /root/.ssh/authorized_keys 192.168.8.66:/root/.ssh/
root@192.168.8.66’s password:
authorized_keys 100% 401 0.4KB/s 00:00
3、远程连接测试
[root@Ansible ~]# vim /etc/ansible/hosts --文件末尾添加以下内容
[web]
192.168.8.55

[root@Ansible ~]# ansible web -m command -a ‘uptime’
192.168.8.55 | SUCCESS | rc=0 >>
14:56:03 up 12:53, 4 users, load average: 0.00, 0.01, 0.05
至此,Ansible的安装配置已经完成,接下来进行模块的讲解。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值