Created
November 11, 2015 08:17
-
-
Save gigablah/b6d43f2bcdc5e86fd5d4 to your computer and use it in GitHub Desktop.
Update Docker containers with Ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Spin up a container | |
hosts: localhost | |
connection: local | |
gather_facts: False | |
sudo: False | |
vars: | |
base_image: gigablah/alpine-python | |
container_name: ansible_test | |
tasks: | |
- name: Remove the base container if it exists | |
local_action: command docker rm -f {{ container_name }} | |
failed_when: False | |
- name: Start the base container | |
local_action: command docker run -d -t --name {{ container_name }} {{ base_image }} bash | |
- name: Add the container to the inventory | |
add_host: name={{ container_name }} | |
- name: Configure the container | |
hosts: ansible_test | |
connection: docker | |
vars: | |
image: gigablah/ansible_test | |
pre_tasks: | |
- name: Install packages | |
raw: apk add -U curl tar wget ca-certificates php-cli php-json php-phar php-openssl git perl openssh-client | |
- name: Install Composer | |
raw: curl -sS https://getcomposer.org/installer | php -- --install-dir=bin --filename=composer | |
- name: Misc | |
raw: mkdir -p /root/.ssh | |
post_tasks: | |
- name: Commit the container to an image | |
local_action: command docker commit {{ inventory_hostname }} {{ image }} | |
- name: Stop the running container | |
local_action: command docker kill {{ inventory_hostname }} | |
- name: Remove the container | |
local_action: command docker rm {{ inventory_hostname }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment