Linux中部署Ansible服务程序

部署Ansible服务程序

实验受控主机信息

操作系统IP地址功能用途
centos 8192.168.10.20Ansible服务
centos 8192.168.10.21dev
centos 8192.168.10.22test
centos 8192.168.10.23prod
centos 8192.168.10.24prod
centos 8192.168.10.25balancers

更改网络连接模式

在“虚拟机设置”界面中,将“网络适配器”的“网络连接”选项调整为“桥接模式”

配置软件仓库

vim /etc/yum.repos.d/Centos-8.repo 
#在原有软件仓库配置的下方,追加以下内容
[ansible]
name=ansible - mirrors.aliyun.com
#failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/8/configmanagement/x86_64/ansible-29/
gpgcheck=0
#gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

安装!

dnf install -y ansible

安装完毕后,Ansible服务便默认已经启动。使用–version参数可以看到Ansible服务的版本及配置信息。

[root@localhost g]# ansible --version
ansible 2.9.27
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Mar 19 2021, 05:13:41) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]

设置主机清单

修改主机清单文件

#直接全部删除,添加以下内容
[root@localhost g]# vim /etc/ansible/hosts 
#开发机
[dev]	
192.168.10.21
#测试机
[test]	
192.168.10.22
#产品机
[prod]	
192.168.10.23
192.168.10.24
#负载均衡机
[balancers]	
192.168.10.25
[root@localhost g]# ansible-inventory --graph
@all:
  |--@balancers:
  |  |--192.168.10.25
  |--@dev:
  |  |--192.168.10.21
  |--@prod:
  |  |--192.168.10.23
  |  |--192.168.10.24
  |--@test:
  |  |--192.168.10.22
  |--@ungrouped:

Ansible常用变量汇总

参数作用
ansible_ssh_host受管主机名
ansible_ssh_port端口号
ansible_ssh_user默认账号
ansible_ssh_pass默认密码
ansible_shell_typeShell终端类型

继续修改主机清单文件

[root@localhost g]# vim /etc/ansible/hosts 
#开发机
[dev]	
192.168.10.21
#测试机
[test]	
192.168.10.22
#产品机
[prod]	
192.168.10.23
192.168.10.24
#负载均衡机
[balancers]	
192.168.10.25
[all:vars]
ansible_user=root
ansible_password=000000

将Ansible主配置文件中的第71行设置成默认不需要SSH协议的指纹验证,以及将第107行设置成默认执行剧本时所使用的管理员名称为root

vim /etc/ansible/ansible.cfg 
 68 #roles_path    = /etc/ansible/roles
 69 
 70 # uncomment this to disable SSH key host checking
 71 host_key_checking = False
 72 
 73 # change the default callback, you can only have one 'stdout' type	enabled at a time.
 74 #stdout_callback = skippy
105 # default user to use for playbooks if user is not specified
106 # (/usr/bin/ansible will use current user as default)
107 remote_user = root
108 
109 # logging is off by default unless this path is defined
110 # if so defined, consider logrotate

不需要重启服务,在以上操作完全搞定后就可以开始后面的实验了

测试

#测试是否ping通
ansible all -m ping

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

怪兽王

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

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

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

打赏作者

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

抵扣说明:

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

余额充值