在alpine镜像中添加ansible服务

 2023-12-24  阅读 2  评论 0

摘要:使用apk add ansible即可在alpine镜像中添加ansible服务。 添加步骤 在alpine中使用ansible需要如下几步 file 在Dockerfile中添加上面的语句: #update apk for install RUN apk update #install ansible and openssh RUN apk add ansible openssh #init ansible hosts file

在alpine镜像中添加ansible服务

使用apk add ansible即可在alpine镜像中添加ansible服务。

添加步骤

在alpine中使用ansible需要如下几步

file

在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.166.6.163.172)进行沟通,事先设定ssh通路,可以使用ssh-copy-id

/ # ssh-copy-id 192.166.6.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.166.6.163.172 (192.166.6.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.166.6.163.172's password:   Number of key(s) added: 1  Now try logging into the machine, with:  "ssh '192.166.6.163.172'"  and check to make sure that only the key(s) you wanted were added.  / #

ssh通路确认

/ # ssh 192.166.6.163.172 hostname  occluster  / #

ansible动作确认

/ # echo "192.166.6.163.172" >>/etc/ansible/hosts  / # ansible 192.166.6.163.172 -m ping  192.166.6.163.172 | SUCCESS => {    "changed": false,     "failed": false,     "ping": "pong"  }  / #

提示:现在腾讯云新人点击注册然后实名认证后,可以点此一键领取2860元代金券,然后点此进入腾讯云活动页面参加优惠力度非常大的腾讯云3年和5年时长服务器活动,一次性买多年,免得续费贵,这样就可以获得最大的优惠折扣,省钱。

版权声明:xxxxxxxxx;

原文链接:https://lecms.nxtedu.cn/yunzhuji/130905.html

发表评论:

验证码

管理员

  • 内容1196553
  • 积分0
  • 金币0
关于我们
lecms主程序为免费提供使用,使用者不得将本系统应用于任何形式的非法用途,由此产生的一切法律风险,需由使用者自行承担,与本站和开发者无关。一旦使用lecms,表示您即承认您已阅读、理解并同意受此条款的约束,并遵守所有相应法律和法规。
联系方式
电话:
地址:广东省中山市
Email:admin@qq.com
注册登录
注册帐号
登录帐号

Copyright © 2022 LECMS Inc. 保留所有权利。 Powered by LECMS 3.0.3

页面耗时0.0103秒, 内存占用335.85 KB, 访问数据库18次

  • 我要关灯
    我要开灯
  • 客户电话
    lecms

    工作时间:8:00-18:00

    客服电话

    电子邮件

    admin@qq.com

  • 官方微信

    扫码二维码

    获取最新动态

  • 返回顶部