init commit
This commit is contained in:
11
1.Docker/ansible.cfg
Normal file
11
1.Docker/ansible.cfg
Normal file
@@ -0,0 +1,11 @@
|
||||
[defaults]
|
||||
inventory = hosts
|
||||
remote_user = root
|
||||
private_key_file = ~/.ssh/id_rsa
|
||||
host_key_checking = False
|
||||
retry_files_enabled = False
|
||||
roles_path = ./roles
|
||||
|
||||
[diff]
|
||||
always = false
|
||||
context = 5
|
3
1.Docker/docker-init.sh
Executable file
3
1.Docker/docker-init.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
ansible-playbook docker-init.yml -l main
|
17
1.Docker/docker-init.yml
Normal file
17
1.Docker/docker-init.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
- hosts: all
|
||||
roles:
|
||||
- role: vasyakrg.docker_install
|
||||
tags: docker
|
||||
become: true
|
||||
|
||||
vars:
|
||||
docker_user: "root"
|
||||
docker_additional_service_opts: |
|
||||
{
|
||||
"exec-opts": ["native.cgroupdriver=systemd"],
|
||||
"log-driver": "json-file",
|
||||
"log-opts": {
|
||||
"max-size": "100m"
|
||||
},
|
||||
"storage-driver": "overlay2"
|
||||
}
|
3
1.Docker/hosts
Normal file
3
1.Docker/hosts
Normal file
@@ -0,0 +1,3 @@
|
||||
[main]
|
||||
web ansible_ssh_host=95.217.182.112
|
||||
node1 ansible_ssh_host=95.216.205.111
|
3
1.Docker/requirements.yml
Normal file
3
1.Docker/requirements.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
- name: vasyakrg.docker_install
|
||||
src: git+https://github.com/vasyakrg/docker_install.git
|
||||
version: origin/master
|
24
1.Docker/roles/vasyakrg.docker_install/.travis.yml
Normal file
24
1.Docker/roles/vasyakrg.docker_install/.travis.yml
Normal file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
language: python
|
||||
python: "2.7"
|
||||
sudo: required
|
||||
dist: trusty
|
||||
|
||||
before_install:
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq python-apt python-pycurl
|
||||
|
||||
install:
|
||||
- sudo pip install ansible
|
||||
- echo -e 'localhost ansible_connection=local' > tests/inventory
|
||||
- echo -e '[defaults]\nroles_path = ../\nhostfile = ./tests/inventory' > ansible.cfg
|
||||
|
||||
script:
|
||||
- ansible-playbook --syntax-check tests/role.yml
|
||||
- ansible-playbook -v --diff tests/role.yml
|
||||
- ansible-playbook -v --diff tests/role.yml
|
||||
- >
|
||||
ansible-playbook tests/role.yml
|
||||
| grep -q 'changed=0.*failed=0'
|
||||
&& (echo 'Idempotence test: pass' && exit 0)
|
||||
|| (echo 'Idempotence test: fail' && exit 1)
|
21
1.Docker/roles/vasyakrg.docker_install/LICENSE.txt
Normal file
21
1.Docker/roles/vasyakrg.docker_install/LICENSE.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Marvin Pinto
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
59
1.Docker/roles/vasyakrg.docker_install/README.md
Normal file
59
1.Docker/roles/vasyakrg.docker_install/README.md
Normal file
@@ -0,0 +1,59 @@
|
||||
docker
|
||||
======
|
||||
This Ansible role enables people to install the latest Docker on an Ubuntu-like
|
||||
system. It also provides a handy library function to validate that the Docker
|
||||
daemon is running and functional.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
This role will only work on an Ubuntu-like system.
|
||||
|
||||
Role Variables
|
||||
--------------
|
||||
|
||||
```yaml
|
||||
# Any additional docker service options
|
||||
# Example: '--dns 8.8.8.8 --dns 8.8.4.4 --userns-remap=default'
|
||||
# docker_additional_service_opts: |
|
||||
# {
|
||||
# "userns-remap": "default",
|
||||
# "dns": [
|
||||
# "8.8.8.8",
|
||||
# "8.8.4.4"
|
||||
# ]
|
||||
# }
|
||||
docker_additional_service_opts: |
|
||||
{}
|
||||
```
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
Install this module from Ansible Galaxy into the './roles' directory:
|
||||
```bash
|
||||
- name: vasyakrg.docker_install
|
||||
src: git+https://github.com/vasyakrg/docker_install.git
|
||||
version: origin/master
|
||||
```
|
||||
|
||||
Use it in a playbook as follows:
|
||||
```yaml
|
||||
- hosts: all
|
||||
roles:
|
||||
- role: vasyakrg.docker_install
|
||||
tags: docker
|
||||
become: true
|
||||
|
||||
vars:
|
||||
docker_user: "vasyansk"
|
||||
docker_additional_service_opts: |
|
||||
{
|
||||
"exec-opts": ["native.cgroupdriver=systemd"],
|
||||
"log-driver": "json-file",
|
||||
"log-opts": {
|
||||
"max-size": "100m"
|
||||
},
|
||||
"storage-driver": "overlay2"
|
||||
}
|
||||
```
|
5
1.Docker/roles/vasyakrg.docker_install/defaults/main.yml
Normal file
5
1.Docker/roles/vasyakrg.docker_install/defaults/main.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
docker_user: ubuntu
|
||||
docker_version_docker_compose: 1.25.4
|
||||
docker_additional_service_opts: |
|
||||
{}
|
12
1.Docker/roles/vasyakrg.docker_install/handlers/main.yml
Normal file
12
1.Docker/roles/vasyakrg.docker_install/handlers/main.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
- name: 'docker-apt-get-update'
|
||||
become: true
|
||||
apt:
|
||||
update_cache: true
|
||||
|
||||
- name: 'docker-restart-service'
|
||||
become: true
|
||||
service:
|
||||
name: 'docker'
|
||||
state: 'restarted'
|
||||
enabled: 'yes'
|
@@ -0,0 +1 @@
|
||||
{install_date: 'Fri Sep 27 07:53:51 2019', version: origin/master}
|
16
1.Docker/roles/vasyakrg.docker_install/meta/main.yml
Normal file
16
1.Docker/roles/vasyakrg.docker_install/meta/main.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
galaxy_info:
|
||||
author: Vassiliy Yegorov
|
||||
description: |
|
||||
This Ansible role enables people to install the latest Docker on an Ubuntu-like
|
||||
system. It also provides a handy library function to validate that the Docker
|
||||
daemon is running and functional.
|
||||
license: MIT
|
||||
min_ansible_version: 1.4
|
||||
platforms:
|
||||
- name: Ubuntu
|
||||
versions:
|
||||
- trusty
|
||||
galaxy_tags:
|
||||
- docker
|
||||
- ubuntu
|
||||
dependencies: []
|
91
1.Docker/roles/vasyakrg.docker_install/tasks/main.yml
Normal file
91
1.Docker/roles/vasyakrg.docker_install/tasks/main.yml
Normal file
@@ -0,0 +1,91 @@
|
||||
---
|
||||
- name: Install aptitude using apt
|
||||
apt:
|
||||
name: 'aptitude'
|
||||
state: 'latest'
|
||||
update_cache: 'yes'
|
||||
force_apt_get: 'yes'
|
||||
|
||||
- name: 'Install prerequisites'
|
||||
apt:
|
||||
name:
|
||||
- 'apt-transport-https'
|
||||
- 'ca-certificates'
|
||||
- 'curl'
|
||||
- 'software-properties-common'
|
||||
- 'gnupg2'
|
||||
state: 'present'
|
||||
update_cache: yes
|
||||
|
||||
- name: 'Add the docker apt signing key'
|
||||
apt_key:
|
||||
url: 'https://download.docker.com/linux/ubuntu/gpg'
|
||||
|
||||
- name: 'Add the official docker repo'
|
||||
apt_repository:
|
||||
repo: 'deb [arch=amd64] https://download.docker.com/linux/{{ ansible_distribution|lower }} {{ ansible_distribution_release }} stable'
|
||||
state: 'present'
|
||||
|
||||
- name: 'Install docker'
|
||||
apt:
|
||||
name:
|
||||
- 'docker-ce'
|
||||
- 'docker-ce-cli'
|
||||
- 'containerd.io'
|
||||
state: 'present'
|
||||
update_cache: yes
|
||||
|
||||
- name: 'Create the /etc/docker directory'
|
||||
file:
|
||||
path: '/etc/docker'
|
||||
state: 'directory'
|
||||
mode: '0700'
|
||||
|
||||
- name: 'Add any additional docker startup options via the daemon.json config file'
|
||||
copy:
|
||||
content: "{{ docker_additional_service_opts }}"
|
||||
dest: '/etc/docker/daemon.json'
|
||||
owner: 'root'
|
||||
group: 'root'
|
||||
mode: '0600'
|
||||
notify: 'docker-restart-service'
|
||||
|
||||
- name: 'Start the docker service'
|
||||
service:
|
||||
name: 'docker'
|
||||
state: 'started'
|
||||
enabled: 'yes'
|
||||
|
||||
- name: 'Add current user to docker group'
|
||||
become: yes
|
||||
user:
|
||||
name: "{{ docker_user }}"
|
||||
groups: 'docker'
|
||||
append: yes
|
||||
|
||||
- name: 'Check that the docker.pid exists'
|
||||
stat:
|
||||
path: /run/docker.pid
|
||||
register: stat_result
|
||||
failed_when: not stat_result.stat.exists
|
||||
tags: docker_check
|
||||
|
||||
- name: 'Result of check docker.pid'
|
||||
debug:
|
||||
msg: 'Docker started'
|
||||
when: stat_result.stat.exists
|
||||
tags: docker_check
|
||||
|
||||
- name: 'Install Docker-compose'
|
||||
get_url:
|
||||
url: 'https://github.com/docker/compose/releases/download/{{ docker_version_docker_compose }}/docker-compose-Linux-x86_64'
|
||||
dest: /usr/local/bin/docker-compose
|
||||
mode: 'a+x'
|
||||
tags: docker_compose_only
|
||||
|
||||
- name: 'Create symlink to docker-compose'
|
||||
file:
|
||||
src: '/usr/local/bin/docker-compose'
|
||||
dest: '/usr/bin/docker-compose'
|
||||
state: 'link'
|
||||
tags: docker_compose_only
|
30
1.Docker/roles/vasyakrg.docker_install/tests/role.yml
Normal file
30
1.Docker/roles/vasyakrg.docker_install/tests/role.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
---
|
||||
- hosts: 'localhost'
|
||||
roles:
|
||||
- role: 'docker_install'
|
||||
become: true
|
||||
tasks:
|
||||
- name: 'Check that the docker.pid exists'
|
||||
stat:
|
||||
path: /run/docker.pid
|
||||
register: stat_result
|
||||
failed_when: stat_result.stat.exists != true
|
||||
|
||||
- name: 'Result of check docker.pid'
|
||||
debug:
|
||||
msg: 'Docker started'
|
||||
when: stat_result.stat.exists
|
||||
|
||||
- name: 'Pull in the latest nginx container'
|
||||
become: true
|
||||
docker_image:
|
||||
name: 'nginx:latest'
|
||||
when: stat_result.stat.exists
|
||||
|
||||
- name: 'Start the nginx container'
|
||||
become: true
|
||||
docker_container:
|
||||
name: 'nginx'
|
||||
image: 'nginx:latest'
|
||||
state: 'started'
|
||||
when: stat_result.stat.exists
|
Reference in New Issue
Block a user