init commit

This commit is contained in:
Vassiliy Yegorov
2020-07-08 16:03:52 +07:00
commit edaa556a5e
30 changed files with 633 additions and 0 deletions

View 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)

View 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.

View 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"
}
```

View File

@@ -0,0 +1,5 @@
---
docker_user: ubuntu
docker_version_docker_compose: 1.25.4
docker_additional_service_opts: |
{}

View 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'

View File

@@ -0,0 +1 @@
{install_date: 'Fri Sep 27 07:53:51 2019', version: origin/master}

View 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: []

View 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

View 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