【docker】ansible安装笔记
发表于:2023-12-29 |

前言

记录ansible安装

流程

1 准备好需要通信的公钥私钥,准备个主机清单hosts:

vim ./hosts


ip写ansible到时候去连的ip

[fe-servers]

xxxx.xx.x.x.x

xxxx.xx.x.x.x

2 构建镜像

FROM centos:7

# 安装必要依赖,openssh-clients是为了支持ssh连接
RUN yum -y install wget curl vim openssh-clients
RUN wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
RUN yum clean all
RUN yum makecache

# 拷贝公钥私钥进镜像内
COPY ssh /root/.ssh/

# 公钥私钥赋权
RUN chmod 755 ~/.ssh/
RUN chmod 600 ~/.ssh/id_rsa ~/.ssh/id_rsa.pub

# 安装 ansible
RUN yum -y install ansible

# 拷贝主机组清单进 ansible 目录
COPY hosts /etc/ansible/

# 关闭 known_hosts 校验
RUN sed -i 's/^#host_key_checking = False/host_key_checking = False/' /etc/ansible/ansible.cfg
RUN ansible --version

  1. 执行构建命令:
docker build -t ansible:t1 .

3 启动容器

docker run -itd --name ansible ansible:t1

4 测试

docker exec -it ansible ansible all -m command -a "chdir=~ docker ps"

如果连上说明ok,连不上需要自己去ansible机子里执行ssh-copy-id -i .ssh/id_rsa.pub 用户名字@ip

上一篇:
2>/dev/null和>/dev/null 2>&1和2>&1>/dev/null的区别
下一篇:
git强制更新(覆盖)本地仓库与远程仓库一致