ansible的搭建

本文详细介绍了如何在CentOS7系统环境下搭建Ansible,包括控制主机和客户端主机的安装要求、安装步骤、配置过程,以及SSH密钥的设置,最终通过测试验证了Ansible的正确配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 安装

一台控制主机:60.60.1.31

三台客户端主机:

60.60.1.30

60.60.1.32

60.60.1.33

安装要求:

控制服务器:需要安装 Python2.6/2.7

管理服务器:需要安装 Python2.4 以上版本,若低于 Python2.5 需要安装 pythonsimplejson; 若启用了 selinux,则需要安装 libselinux-python。

本次安装基于CentOS7系统环境、Python2.7.5、ansible用户。

 

  1. yum安装

yum install epel-release

yum install ansible

 

  1. 配置控制主机

 vim /etc/ansible/hosts

[web]

60.60.1.30

[p60]

60.60.1.13

60.60.1.14

60.60.1.15

60.60.1.17

60.60.1.19

[p193]

192.168.193.10

192.168.193.11

192.168.193.12

192.168.193.13

192.168.193.16

4、配置客户端主机

   useradd  ansible 添加ansible用户

   passwd  ansible 设置密码

   cd /home/ansible

   mkdir  .ssh 建一个目录

   chown -R ansible.ansible .ssh 修改目录权限

   vim /etc/sudoers  添加一行

   ansible            ALL=(ALL)     NOPASSWD: ALL

5、配置控制主机SSH密钥

   ssh-keygen -t rsa

   将公钥拷贝到管理主机中.ssh/authorized_keys文件中,实现免密码登录远程管理主机

ssh-copy-id -i ~/.ssh/id_rsa.pub ansible@60.60.1.30

ssh-copy-id -i ~/.ssh/id_rsa.pub ansible@60.60.1.32

ssh-copy-id -i ~/.ssh/id_rsa.pub ansible@60.60.1.33

注:ssh-copy-id命令会自动将id_rsa.pub文件的内容追加到远程主机ansible用户下.ssh/authorized_keys文件中。

 

6、ansible配置

   vim /etc/ansible/ansible.cfg

  1> 禁用每次执行ansbile命令检查ssh key host

host_key_checking = False

2> 开启日志记录

log_path = /var/log/ansible.log

3> ansible连接加速配置

[accelerate]

#accelerate_port = 5099

accelerate_port = 10000

#accelerate_timeout = 30

#accelerate_connect_timeout = 5.0

 

# If set to yes, accelerate_multi_key will allow multiple

# private keys to be uploaded to it, though each user must

# have access to the system via SSH to add a new key. The default

# is "no".

accelerate_multi_key = yes

 

7、测试

 ansible all -m ping

结果如下

[ansible@60-60-1-31 ~]$ ansible all -s -m ping

[DEPRECATION WARNING]: The sudo command line option has been deprecated in favor of the "become" command line arguments. This feature will be removed

in version 2.6. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

192.168.193.10 | SUCCESS => {

    "changed": false,

    "ping": "pong"

}

192.168.193.12 | SUCCESS => {

    "changed": false,

    "ping": "pong"

}

192.168.193.11 | SUCCESS => {

    "changed": false,

    "ping": "pong"

}

192.168.193.13 | SUCCESS => {

    "changed": false,

    "ping": "pong"

}

60.60.1.30 | SUCCESS => {

 

8、

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值