How to add ansible service in alpine image

How to add ansible service in alpine image

Use apk add ansible to add the ansible service to the alpine image.

Add Steps

Using Ansible in Alpine requires the following steps

Dockerfile

Add the above statement in 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/*

Using Mirror

Pull the image

About 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 ~]#

use

Confirm the version

[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]
/ #

To communicate with the host (192.168.163.172), set up the ssh channel in advance and use 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
[email protected]'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 access confirmation

/#ssh 192.168.163.172 hostname
occluster
/ #

ansible action confirmation

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

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Telnet is moved to busybox-extras in Alpine image
  • Implementation of tomcat image created with dockerfile based on alpine
  • Implementation of crawler Scrapy image created by dockerfile based on alpine
  • How to build php-nginx-alpine image from scratch in Docker
  • How to deploy tomcat in batches with ansible
  • Sample code for installing Ansible under Centos
  • Python ansible service and script writing
  • Ansible as a Python module library method example
  • Detailed tutorial on using the Linux automated operation and maintenance tool Ansible
  • Cluster operation and maintenance automation tool Ansible uses playbook to install the zabbix client

<<:  Summary of common problems in downloading and installing MySQL 5.7 on Win7 64-bit

>>:  JS implements random roll call system

Recommend

Vue implements adding watermark to uploaded pictures

This article shares the specific implementation c...

What does href=# mean in a link?

Links to the current page. ------------------- Com...

Solutions to the problem of table nesting and border merging

【question】 When the outer table and the inner tab...

Essential Handbook for Web Design 216 Web Safe Colors

The color presentation on a web page will be affec...

Prevent HTML and JSP pages from being cached and re-fetched from the web server

After the user logs out, if the back button on the...

CocosCreator ScrollView optimization series: frame loading

Table of contents 1. Introduction 2. Analysis of ...

We're driving IE6 to extinction on our own

In fact, we wonder every day when IE6 will really...

Sample code for implementing multi-application deployment using tomcat+nginx

Table of contents Multi-application deployment 1-...

React.js framework Redux basic case detailed explanation

react.js framework Redux https://github.com/react...

Delete the image operation of none in docker images

Since I usually use the docker build command to g...

CSS achieves highly adaptive full screen

When writing my own demo, I want to use display:f...