diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..43878b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# ---> Ansible +*.retry + diff --git a/README.md b/README.md index 1827652..d7d5d27 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,22 @@ -# Ansible-Docker - -Ansible playbook that provisions a server to run Docker. \ No newline at end of file +# Ansible-Docker + +Ansible playbook that provisions a server to run Docker. + +## Example + +Execute playbook with needed variables to setup a server to run Docker. + +`ansible-playbook -i hosts site.yml` + +```yml +--- +# file: hosts + +docker: + hosts: + doc01: + ansible_host: 10.10.10.14 + + vars: + ansible_user: ansible +``` diff --git a/docker.yml b/docker.yml new file mode 100644 index 0000000..eb693a9 --- /dev/null +++ b/docker.yml @@ -0,0 +1,7 @@ +--- +# file: docker.yml + +- hosts: docker + become: true + roles: + - docker diff --git a/hosts.yml b/hosts.yml new file mode 100644 index 0000000..fc6b8b3 --- /dev/null +++ b/hosts.yml @@ -0,0 +1,10 @@ +--- +# file: hosts + +docker: + hosts: + doc1: + ansible_host: 10.10.10.14 + + vars: + ansible_user: ansible diff --git a/roles/docker/defaults/main.yml b/roles/docker/defaults/main.yml new file mode 100644 index 0000000..0b70d08 --- /dev/null +++ b/roles/docker/defaults/main.yml @@ -0,0 +1,9 @@ +--- +# file: roles/docker/defaults/main.yml + +docker_repo_url: "https://download.docker.com/linux/rhel/docker-ce.repo" +docker_manager_enabled: false +docker_manager_account: "{{ ansible_user }}" +docker_service_options: { + "selinux-enabled": true +} diff --git a/roles/docker/handlers/main.yml b/roles/docker/handlers/main.yml new file mode 100644 index 0000000..4f85125 --- /dev/null +++ b/roles/docker/handlers/main.yml @@ -0,0 +1,7 @@ +--- +# file: roles/docker/handlers/main.yml + +- name: Restart docker + service: + name: docker + state: restarted diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml new file mode 100644 index 0000000..79ebbdf --- /dev/null +++ b/roles/docker/tasks/main.yml @@ -0,0 +1,37 @@ +--- +# file: roles/docker/tasks/main.yml + +- name: Add Docker repository + get_url: + url: "{{ docker_repo_url }}" + dest: '/etc/yum.repos.d/docker-ce.repo' + +- name: Install packages + package: + name: + - docker-ce + - docker-ce-cli + - containerd.io + - docker-compose-plugin + state: latest + tags: packages + +- name: Add manager user to Docker group + user: + name: "{{ docker_manager_account }}" + groups: docker + append: yes + when: docker_manager_enabled + +- name: Configure Docker service options + copy: + content: "{{ docker_service_options | to_nice_json }}" + dest: /etc/docker/daemon.json + when: docker_service_options.keys() | length > 0 + notify: Restart docker + +- name: Start and enable Docker + service: + name: docker + state: started + enabled: yes diff --git a/site.yml b/site.yml new file mode 100644 index 0000000..0378cec --- /dev/null +++ b/site.yml @@ -0,0 +1,4 @@ +--- +## This playbook deploys the whole application stack in this site. + +- import_playbook: docker.yml