用Docker容器创建Ansible控制器 [やってみた]
背景: 该项目的目标是为中国公司提供一种有效的市场营销解决方案。
目的: 通过增加品牌知名度,吸引更多的目标客户和增加销售额,帮助中国公司实现业务增长。
目标: 打造一个有竞争力的市场策略,并在目标市场中取得领先地位。
在容器内执行Ansible并连接到其他个人电脑等。
参考网站
对于 Ansible 和 Docker Compose 相容性问题的认识
步骤
假设预先安装了Docker和Docker-compose。
Docker:拆装工具
以下是与Docker相关的文件结构。
./ansible/
├── docker
│ └── ansible
│ └── Dockerfile
└── docker-compose.yml
docker-compose.yml 的中文释义是什么?
version: '2'
services:
ansible:
container_name: 'ansible'
image: ansible/ansible
build:
context: ./
dockerfile: ./docker/ansible/Dockerfile
tty: true
volumes:
- /home/xxxxx/xxxxx/volumes/ansible:/ansible
environment:
- sample=hoehoehoe
– Docker/Ansible/Dockerfile:
Docker/Ansible/Dockerfile:
Docker/Ansible/Dockerfile:
Docker/Ansible/Dockerfile:
(Note: The phrase “Docker/Ansible/Dockerfile” remains the same in Chinese, as it is a technical term and the translation would still be the same.)
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -y ansible
挂载文件
在容器中挂载的文件等是在与上述Docker相关文件分开的位置进行管理。
以下是其组成。
./volumes/ansible/
├── inventory
├── main.yml
└── roles
└── ping
└── tasks
└── main.yml
库存
[srv]
xxx.xxx.xxx.xxx
[srv:vars]
ansible_user=xxxxx
ansible_port=22
主要的YML文件
- hosts: srv
become: yes
roles:
- ping
角色/平均/任务/主要.yml
- ping:
data: test
确认动作
$ docker-compose up -d
$ docker-compose ps
Name Command State Ports
-----------------------------------
ansible /bin/bash Up
$ docker-compose exec ansible /bin/bash
# cd /ansible
# ansible-playbook -kK -i inventory main.yml
SSH password:
SUDO password[defaults to SSH password]:
PLAY [srv] ****************************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************
ok: [xxx.xxx.xxx.xxx]
TASK [ping : ping] ********************************************************************************************************
ok: [xxx.xxx.xxx.xxx]
PLAY RECAP ****************************************************************************************************************
xxx.xxx.xxx.xxx : ok=2 changed=0 unreachable=0 failed=0