目的
色々な環境下でTerraformやAnsibleをいちいち構築するのは大変なので、今回はそれらをコンテナ化する。
構築
docker-compose.yml
version: '3.9'
services:
terasible:
build:
context: .
image: "terasible:1.0"
container_name: "terasible"
working_dir: /etc/terasible
tty: true
volumes:
- "/work/:/etc/terasible"
Dockerfile
FROM ubuntu:22.04
RUN apt -y update && apt -y install software-properties-common && apt-add-repository --yes --update ppa:ansible/ansible && apt -y install ansible wget unzip
RUN apt -y install sshpass genisoimage nano vim
RUN wget https://releases.hashicorp.com/terraform/1.5.4/terraform_1.5.4_linux_amd64.zip
RUN unzip terraform_1.5.4_linux_amd64.zip
RUN cp terraform /usr/local/bin
RUN echo "" | echo "" | echo "" | ssh-keygen
RUN cat ~/.ssh/id_rsa.pub
ADD "https://www.random.org/cgi-bin/randbyte?nbytes=10&format=h" /dev/null
RUN sshpass -p hiyiir ssh-copy-id -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa.pub root@172.24.20.3
RUN sshpass -p hiyiir ssh-copy-id -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa.pub shoma@172.24.20.3