佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > 在alpine鏡像中添加ansible服務(wù)的方法

在alpine鏡像中添加ansible服務(wù)的方法

熱門標(biāo)簽:美圖手機(jī) 百度競(jìng)價(jià)點(diǎn)擊價(jià)格的計(jì)算公式 硅谷的囚徒呼叫中心 網(wǎng)站建設(shè) 智能手機(jī) 阿里云 檢查注冊(cè)表項(xiàng) 使用U盤裝系統(tǒng)

使用apk add ansible即可在alpine鏡像中添加ansible服務(wù)。

添加步驟

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

Dockerfile

在Dockerfile中添加上面的語(yǔ)句:

#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)鏈接

標(biāo)簽:湖北 黃山 湘潭 山南 懷化 煙臺(tái) 通遼 賀州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《在alpine鏡像中添加ansible服務(wù)的方法》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    上虞市| 赤峰市| 佛坪县| 上杭县| 达拉特旗| 定边县| 信阳市| 冀州市| 徐闻县| 如皋市| 彭阳县| 崇仁县| 班玛县| 眉山市| 通海县| 阿拉尔市| 高邮市| 东乌珠穆沁旗| 临沧市| 中西区| 昌乐县| 武夷山市| 凉山| 横峰县| 灵宝市| 夏邑县| 稷山县| 韶山市| 三河市| 仙桃市| 贡山| 石景山区| 浦北县| 万源市| 德江县| 怀化市| 涪陵区| 宝丰县| 湾仔区| 江都市| 鹿邑县|