在alpine镜像中添加ansible服务的方法

今天小编就为大家分享一篇关于在alpine镜像中添加ansible服务的方法,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧使用apk add ansible即可在alpine镜像中添加ansible服务。添加步骤在alpine中使用ansible需要如下几步

Dockerfile在Dockerfile中添加上面的语句:1234567891011#update apk for installRUN apk update#install ansible and opensshRUN apk add ansible openssh#init ansible hosts fileRUN mkdir -p /etc/ansibleRUN echo "localhost" >/etc/ansible/hosts#init rsa ssh key pairRUN ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa#delete cache filesRUN rm -rf /var/cache/apk/*使用镜像拉取镜像大概103M左右1234567891011121314151617[root@occluster ~]# docker pull liumiaocn/ansibleUsing default tag: latestTrying to pull repository docker.io/liumiaocn/ansible ...latest: Pulling from docker.io/liumiaocn/ansibleff3a5c916c92: Already exists42a81541f983: Pull complete86602ac17bcb: Pull complete73cb14e49a3f: Pull completebdfcad59d746: Pull complete455ffeaa5bf1: Pull completedff32643cfa5: Pull completeDigest: sha256:46284f3d3b9e3880f9b65fa6b1fb225b19bc88222badf74aa85936aabc24090fStatus: Downloaded newer image for docker.io/liumiaocn/ansible:latest[root@occluster ~]#[root@occluster ~]# docker images |grep ansibledocker.io/liumiaocn/ansible         latest       8a5cfdf8243f    Less than a second ago  103 MB[root@occluster ~]#使用进行版本确认123456789[root@occluster ~]# docker run -it --name ansible liumiaocn/ansible sh/ # ansible --versionansible 2.4.1.0config file = Noneconfigured module search path = [u'http://www.cncsto.com', u'/usr/share/ansible/plugins/modules']ansible python module location = /usr/lib/python2.7/site-packages/ansibleexecutable location = /usr/bin/ansiblepython version = 2.7.14 (default, Dec 14 2017, 15:51:29) [GCC 6.4.0]/ #与宿主机(192.168.163.172)进行沟通,事先设定ssh通路,可以使用ssh-copy-id1234567891011121314/ # 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 installedexpr: warning: '^ERROR: ': using '^' as the first characterof 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 keysroot@192.168.163.172's password:Number of key(s) added: 1Now 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通路确认123/ # ssh 192.168.163.172 hostnameoccluster/ #ansible动作确认12345678/ # echo "192.168.163.172" >>/etc/ansible/hosts/ # ansible 192.168.163.172 -m ping192.168.163.172 | SUCCESS => {"changed": false,"failed": false,"ping": "pong"}/ #总结以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值

(0)

相关推荐