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

使用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"
}
/ #

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对我们的支持。如果你想了解更多相关内容请查看下面相关链接

(0)

相关推荐

  • Docker从零构建php-nginx-alpine镜像的方法

    虽然之前也曾用docker环境运行了一些项目,但对于镜像这块还不是很理解,且鉴于网上现成的镜像都包含太多用不到的库,所以决定从零开始构建一个自己的镜像. alpine linux为基础镜像 docker pull gliderlabs/alpine alpine linux 镜像地址 目前最新的tag是3.8版本,镜像只有4M的大小,非常的精简. 运行镜像 docker run -it gliderlabs/alpine 运行后可以看到里面有基本的linux文件系统,这里不做演示,有兴趣者可自行

  • linux 自动化运维工具ansible的使用详细教程

    一.ansible简介 1.ansible ansible是新出现的自动化运维工具,基于Python研发.糅合了众多老牌运维工具的优点实现了批量操作系统配置.批量程序的部署.批量运行命令等功能.仅需在管理工作站上安装ansible程序配置被管控主机的IP信息,被管控的主机无客户端.ansible应用程序存在于epel(第三方社区)源,依赖于很多python组件.主要包括: (1).连接插件connection plugins:负责和被监控端实现通信: (2).host inventory:指定操

  • python ansible服务及剧本编写

    第1章 ansible软件概念说明 python语言是运维人员必会的语言,而ansible是一个基于Python开发的自动化运维工具 (saltstack).其功能实现基于SSH远程连接服务:ansible可以实现批量系统配置.批量软件部署.批量文件拷贝.批量运行命令等功能 ansible软件相关参考链接信息: http://docs.ansible.com/ansible/intro_installation.html http://www.ansible.com.cn/ http://doc

  • Centos下安装Ansible的示例代码

    ansible ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)的优点,实现了批量系统配置.批量程序部署.批量运行命令等功能. ansible是基于模块工作的,本身没有批量部署的能力.真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架.主要包括: 连接插件connection plugins:负责和被监控端实现通信: host inventory:指定操作的主机,是一个

  • 基于alpine用dockerfile创建的爬虫Scrapy镜像的实现

    一.下载alpine镜像 [root@DockerBrian ~]# docker pull alpine Using default tag: latest Trying to pull repository docker.io/library/alpine ... latest: Pulling from docker.io/library/alpine 4fe2ade4980c: Pull complete Digest: sha256:621c2f39f8133acb8e64023a94

  • Alpine镜像中telnet转移至busybox-extras

    Alpine镜像中的telnet在3.7版本后被转移至busybox-extras包中,需要使用apk单独安装. 现象 Alpine版本为3.8, 不再有指向busybox的telent ~ # cat /etc/alpine-release 3.8.0 ~ # ~ # ls /usr/bin/ |grep -w busybox |grep telnet ~ # 原因 确认了相关的issue发现,在Alpine3.7时就已经有了这个变化:https://github.com/gliderlabs

  • ansible批量部署tomcat的方法

    1.1 构建目录结构 此操作是安装nginx+mysql+tomcat+db的目录结构,可以参考一下,不错~ mkdir -p /ansible/roles/{nginx,mysql,tomcat,db}/{defaults,files,handlers,meta,tasks,templates,vars} defaults 默认寻找路径 tasks 存放playbooks路径 files 存放文件和脚本包,copy模块文件搜索路径 templates 模版存放路径 handlers notif

  • 基于alpine用dockerfile创建的tomcat镜像的实现

    1.下载alpine镜像 [root@docker43 ~]# docker pull alpine Using default tag: latest Trying to pull repository docker.io/library/alpine ... latest: Pulling from docker.io/library/alpine 4fe2ade4980c: Pull complete Digest: sha256:621c2f39f8133acb8e64023a94dbd

  • 集群运维自动化工具ansible之使用playbook安装zabbix客户端

    之前介绍了关于ansible的安装与使用(包括模块与playbook使用,地址是http://www.jb51.net/article/52154.htm),今天介绍一下如何使用playbook来部署zabbix客户端. ansible服务端的环境为centos 6.5 x86_64系统 ansible客户端环境为centos 6.3 x86_64系统 目前我的playbook只允许centos或redhat 6系列系统来安装zabbix客户端,并且客户端的版本是2.0.6. 下面是playbo

  • ansible作为python模块库使用的方法实例

    前言 ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)的优点,实现了批量系统配置.批量程序部署.批量运行命令等功能.ansible是基于模块工作的,本身没有批量部署的能力.真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架. 主要包括: (1).连接插件connection plugins:负责和被监控端实现通信: (2).host inventory:指定操作的主机,

随机推荐