Dockerfile to run Ansible in CircleCI
Dockerfile to run Ansible in CircleCI.
Dockerfile
to your provisioning
directory:
FROM doomatel/circleci-ansible:3.8.0-2.9.0
ADD --chown=circleci:circleci . /home/circleci
RUN sudo chmod 700 /home/circleci/.ssh && sudo chmod 600 /home/circleci/.ssh/id_rsa*
deploy
to your circle.yml
with the following config:
version: 2
jobs:
deploy:
docker:
- image: docker:19.03.4-git
steps:
- checkout
- setup_remote_docker
- add_ssh_keys:
name: DEPLOY - Add SSH keys
fingerprints:
- 11:11:11
- 22:22:22
- run:
name: DEPLOY - make directory for SSH keys
command: mkdir /root/project/provisioning/.ssh
- run:
name: DEPLOY - Copy SSH keys
command: |
cp /root/.ssh/id_rsa_111111 /root/project/provisioning/.ssh/id_rsa_develop
cp /root/.ssh/id_rsa_222222 /root/project/provisioning/.ssh/id_rsa_beta
- deploy:
name: DEPLOY - Run deployment
command: |
docker build /root/project/provisioning -t ansible-deploy
docker run --rm ansible-deploy \
ansible-playbook /home/circleci/deploy.yml \
-i /home/circleci/environments/hosts.ini \
-e env=${CIRCLE_BRANCH} \
--key-file=/home/circleci/id_rsa_${CIRCLE_BRANCH}
11:11:11
+ 111111
and 22:22:22
+ 222222
to your actual SSH key fingerprints.id_rsa_develop
& id_rsa_beta
to your environments. They should be equal to github branches passed in ${CIRCLE_BRANCH}
.
- checkout
- setup_remote_docker
- add_ssh_keys:
name: DEPLOY - Add SSH keys
fingerprints:
- 11:11:11
- 22:22:22
provisioning
) to be able to put it into the context of temporary Docker image.
- run:
name: DEPLOY - make directory for SSH keys
command: mkdir /root/project/provisioning/.ssh
- run:
name: DEPLOY - Copy SSH keys
command: |
cp /root/.ssh/id_rsa_111111 /root/project/provisioning/.ssh/id_rsa_develop
cp /root/.ssh/id_rsa_222222 /root/project/provisioning/.ssh/id_rsa_beta
ansible-deploy
from doomatel/circleci-ansible
image, including SSH keys.
docker build /root/project/provisioning -t ansible-deploy
ansible-deploy
Docker image.
docker run --rm ansible-deploy \
ansible-playbook /home/circleci/deploy.yml \
-i /home/circleci/environments/hosts.ini \
-e env=${CIRCLE_BRANCH} \
--key-file=/home/circleci/id_rsa_${CIRCLE_BRANCH}