在alpine鏡像中添加ansible服務(wù)的方法
使用apk add ansible即可在alpine鏡像中添加ansible服務(wù)。
添加步驟
在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 ~]#
使用
進(jìn)行版本確認(rèn)
[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] / #
與宿主機(jī)(192.168.163.172)進(jìn)行溝通,事先設(shè)定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通路確認(rèn)
/ # ssh 192.168.163.172 hostname occluster / #
ansible動(dòng)作確認(rèn)
/ # 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" } / #
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
- Alpine鏡像中telnet轉(zhuǎn)移至busybox-extras
- 基于alpine用dockerfile創(chuàng)建的tomcat鏡像的實(shí)現(xiàn)
- 基于alpine用dockerfile創(chuàng)建的爬蟲Scrapy鏡像的實(shí)現(xiàn)
- Docker從零構(gòu)建php-nginx-alpine鏡像的方法
- ansible批量部署tomcat的方法
- Centos下安裝Ansible的示例代碼
- python ansible服務(wù)及劇本編寫
- ansible作為python模塊庫使用的方法實(shí)例
- linux 自動(dòng)化運(yùn)維工具ansible的使用詳細(xì)教程
- 集群運(yùn)維自動(dòng)化工具ansible之使用playbook安裝zabbix客戶端
相關(guān)文章
用docker部署RabbitMQ環(huán)境的詳細(xì)介紹
這篇文章主要介紹了用docker部署RabbitMQ環(huán)境,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-07-07利用docker搭建LAMP運(yùn)行環(huán)境教程詳解
LAMP相信對(duì)大家來說都不陌生, Docker是一個(gè)開源的引擎,可以輕松的為任何應(yīng)用創(chuàng)建一個(gè)輕量級(jí)的、可移植的、自給自足的容器,所以這篇文章給大家介紹利用docker快速搭建LAMP運(yùn)行環(huán)境的方法,有需要的朋友們可以參考借鑒,下面來一起看看吧。2016-10-10IDEA集成Docker實(shí)現(xiàn)打包的方法
本文主要介紹了IDEA集成Docker實(shí)現(xiàn)打包的方法,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01Docker創(chuàng)建運(yùn)行多個(gè)mysql容器的方法示例
這篇文章主要介紹了Docker創(chuàng)建運(yùn)行多個(gè)mysql容器,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-10-10docker compose安裝es+kibana 8.12.2的詳細(xì)過程
因云平臺(tái)需要改造,es7升級(jí)為es8,所以記錄一下,es8需要開啟ssl認(rèn)證,需要配置證書,全本帶你用docker安裝,便于后面es8的學(xué)習(xí),這篇文章主要介紹了docker compose安裝es+kibana 8.12.2的詳細(xì)過程,感興趣的朋友跟隨小編一起看看吧2024-05-05docker空間爆滿導(dǎo)致的進(jìn)入容器失敗的解決方案
這篇文章主要介紹了docker空間爆滿導(dǎo)致的進(jìn)入容器失敗的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-03-03