在alpine镜像中添加ansible服务的方法
程序员文章站
2022-07-09 14:11:50
使用apk add ansible即可在alpine镜像中添加ansible服务。
添加步骤
在alpine中使用ansible需要如下几步
dockerfile...
使用apk add ansible即可在alpine镜像中添加ansible服务。
添加步骤
在alpine中使用ansible需要如下几步
dockerfile
在dockerfile中添加上面的语句:
#update apk for install run apk update #install ansible and openssh run apk add ansible openssh #init ansible hosts file run mkdir -p /etc/ansible run echo "localhost" >/etc/ansible/hosts #init rsa ssh key pair run ssh-keygen -t rsa -p "" -f ~/.ssh/id_rsa #delete cache files run rm -rf /var/cache/apk/*
使用镜像
拉取镜像
大概103m左右
[root@occluster ~]# docker pull liumiaocn/ansible using default tag: latest trying to pull repository docker.io/liumiaocn/ansible ... latest: pulling from docker.io/liumiaocn/ansible ff3a5c916c92: already exists 42a81541f983: pull complete 86602ac17bcb: pull complete 73cb14e49a3f: pull complete bdfcad59d746: pull complete 455ffeaa5bf1: pull complete dff32643cfa5: pull complete digest: sha256:46284f3d3b9e3880f9b65fa6b1fb225b19bc88222badf74aa85936aabc24090f status: downloaded newer image for docker.io/liumiaocn/ansible:latest [root@occluster ~]# [root@occluster ~]# docker images |grep ansible docker.io/liumiaocn/ansible latest 8a5cfdf8243f less than a second ago 103 mb [root@occluster ~]#
使用
进行版本确认
[root@occluster ~]# docker run -it --name ansible liumiaocn/ansible sh / # ansible --version ansible 2.4.1.0 config file = none configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/site-packages/ansible executable location = /usr/bin/ansible python version = 2.7.14 (default, dec 14 2017, 15:51:29) [gcc 6.4.0] / #
与宿主机(192.168.163.172)进行沟通,事先设定ssh通路,可以使用ssh-copy-id
/ # ssh-copy-id 192.168.163.172 /usr/bin/ssh-copy-id: info: source of key(s) to be installed: "/root/.ssh/id_rsa.pub" the authenticity of host '192.168.163.172 (192.168.163.172)' can't be established. ecdsa key fingerprint is sha256:uh84xw56lhicxb1b0ufbx/cofhkqhgzjtmlwl3qktoy. are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: info: attempting to log in with the new key(s), to filter out any that are already installed expr: warning: '^error: ': using '^' as the first character of a basic regular expression is not portable; it is ignored /usr/bin/ssh-copy-id: info: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@192.168.163.172's password: number of key(s) added: 1 now try logging into the machine, with: "ssh '192.168.163.172'" and check to make sure that only the key(s) you wanted were added. / #
ssh通路确认
/ # ssh 192.168.163.172 hostname occluster / #
ansible动作确认
/ # echo "192.168.163.172" >>/etc/ansible/hosts / # ansible 192.168.163.172 -m ping 192.168.163.172 | success => { "changed": false, "failed": false, "ping": "pong" } / #
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接