ansible安装配置

1.环境检查与安装要求:

  • 管理节点需要Python>=2.6,并OpenSSH
  • 被管理节点需要python >=2.4,并安装OpenSSH

2.YUM源检查与安装

  • 检查YUM源列表,使用命令yum repolist
  • 安装wget工具,使用命令yum install wget -y
  • 下载并安装EPEL源,使用命令wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 或 yum install -y epel-release

3.安装ansible

  • 使用YUM命令安装Ansible,yum -y install ansible
  • 使用pip命令安装Ansible,pip install ansible

4.ansible配置文件 /etc/ansible

  • ansible配置文件 查看配置文件顺序
  1. ANSIBLE_CONFIG变量
  2. 当前目录下./ansible.cfg
  3. 家目录下~/ansible.cfg
  4. 配置文件 /etc/ansible/ansible.cfg

5.配置ssh远程连接免密码

ssh-keygen -t rsa -P '' #生成密钥
ssh-keygen -f ~/.ssh/id_rsa -N '' #生成密钥

#配置远程免密(ssh-copy-id不能使用时)
sh-copy-id命令报错:-bash: ssh-copy-id: command not found,安装openssh-client
yum -y install openssh-clients
无法安装时可以用一下方式
cat ~/.ssh/id_*.pub | ssh  被管理服务器ip 'cat >> .ssh/authorized_keys'

#复制密钥到远程主机
for i in ip1 ip2 ip3
do
 ssh-copy-id $i
done
posted @ 2024-11-07 09:53  靖11  阅读(73)  评论(0)    收藏  举报