Browse Source

Import

tags/0.0.1^2
Julien Cabillot 2 years ago
parent
commit
5cd506f15a
15 changed files with 398 additions and 1 deletions
  1. +1
    -0
      Jenkinsfile
  2. +38
    -1
      README.md
  3. +29
    -0
      defaults/main.yml
  4. +3
    -0
      handlers/main.yml
  5. +81
    -0
      kitchen.yml
  6. +68
    -0
      meta/main.yml
  7. +20
    -0
      tasks/docker-compose.yml
  8. +7
    -0
      tasks/docker-users.yml
  9. +27
    -0
      tasks/main.yml
  10. +6
    -0
      tasks/setup-Amazon.yml
  11. +46
    -0
      tasks/setup-Debian.yml
  12. +58
    -0
      tasks/setup-RedHat.yml
  13. +7
    -0
      test/integration/default/main.rb
  14. +5
    -0
      tests/test.yml
  15. +2
    -0
      vars/main.yml

+ 1
- 0
Jenkinsfile View File

@@ -0,0 +1 @@
fxPlaybook()

+ 38
- 1
README.md View File

@@ -1,2 +1,39 @@
# ansible-role-docker
ansible-role-docker
===================

Install docker for CentOS / RHEL / Amazon Linux 2.
Based on : https://github.com/geerlingguy/ansible-role-docker/
The geerlingguy role doesn't support RHEL and Amazon.

Requirements
------------

N/A

Role Variables
--------------

N/A

Dependencies
------------

N/A

Example Playbook
----------------

TODO

```yaml
```

License
-------

MIT

Author Information
------------------

FXInnovation Inc

+ 29
- 0
defaults/main.yml View File

@@ -0,0 +1,29 @@
---
# Edition can be one of: 'ce' (Community Edition) or 'ee' (Enterprise Edition).
docker_edition: 'ce'
docker_package: 'docker-{{ docker_edition }}'
docker_package_state: present

# Service options.
docker_service_state: started
docker_service_enabled: true
docker_restart_handler_state: restarted

# Docker Compose options.
docker_install_compose: true
docker_compose_version: "1.22.0"
docker_compose_path: /usr/local/bin/docker-compose

# Used only for Debian/Ubuntu. Switch 'stable' to 'edge' if needed.
docker_apt_release_channel: stable
docker_apt_arch: amd64
docker_apt_repository: "deb [arch={{ docker_apt_arch }}] https://download.docker.com/linux/{{ ansible_distribution|lower }} {{ ansible_distribution_release }} {{ docker_apt_release_channel }}"
docker_apt_ignore_key_error: true

# Used only for RedHat/CentOS/Fedora.
docker_yum_repo_url: https://download.docker.com/linux/{{ (ansible_distribution == "Fedora") | ternary("fedora","centos") }}/docker-{{ docker_edition }}.repo
docker_yum_repo_enable_edge: 0
docker_yum_repo_enable_test: 0

# A list of users who will be added to the docker group.
docker_users: []

+ 3
- 0
handlers/main.yml View File

@@ -0,0 +1,3 @@
---
- name: restart docker
service: "name=docker state={{ docker_restart_handler_state }}"

+ 81
- 0
kitchen.yml View File

@@ -0,0 +1,81 @@
---

driver:
name: "ec2"
associate_public_ip: true
aws_ssh_key_id: "<%= ENV['AWS_SSH_KEY_ID'] %>"
interface: "public"
region: "<%= ENV['AWS_REGION'] %>"
require_chef_omnibus: false
subnet_id: "<%= ENV['AWS_SUBNETID'] %>"
iam_profile_name: "<%= ENV['AWS_IAMPROFILE'] %>"

transport:
name: "ssh"
ssh_key: "<%= ENV['AWS_SSH_KEY'] %>"
username: "ec2-user"
connection_retries: 5
connection_retry_sleep: 30
max_wait_until_ready: 300
# BUG Related to https://github.com/test-kitchen/test-kitchen/pull/1047
max_ssh_sessions: 2

provisioner:
name: "ansible_playbook"
hosts: "all"
ansible_connection: "local"
ansible_verbose: false
ansible_verbosity: 2
require_pip: true
ansible_version: "<%= ENV['KITCHEN_ANSIBLE_VERSION'] %>"
idempotency_test: <%= ENV['KITCHEN_IDEMPOTENCY'] %>
require_chef_for_busser: false
require_ruby_for_busser: false
role_name: "<%= ENV['KITCHEN_ROLENAME'] %>"
roles_path: "."

platforms:
- name: "rhel-7"
driver:
instance_type: "t3.small"
tags:
Name: "tk-<%= ENV['KITCHEN_ROLENAME'] %>"
kitchen: "true"
packer: "true"
- name: "centos-7"
driver:
image_search:
name: "CentOS Linux 7*"
owner-id: "679593333241"
product-code: "aw0evgkw8e5c1q413zgy5pjce"
instance_type: "t3.small"
tags:
Name: "tk-<%= ENV['KITCHEN_ROLENAME'] %>"
kitchen: "true"
packer: "true"
transport:
username: "centos"
- name: "amazon2-2019"
driver:
instance_type: "t3.small"
tags:
Name: "tk-<%= ENV['KITCHEN_ROLENAME'] %>"
kitchen: "true"
packer: "true"

verifier:
name: inspec
sudo: true
reporter:
- cli
- junit:%{platform}_%{suite}_inspec.xml

suites:
- name: "default"
provisioner:
name: "ansible_playbook"
playbook: "tests/test.yml"
verifier:
inspec_tests:
- name: local
path: test/integration/default

+ 68
- 0
meta/main.yml View File

@@ -0,0 +1,68 @@
galaxy_info:
author: FXInnovation Inc
description: Install docker for CentOS / RHEL / Amazon Linux 2.
company: FXInnovation Inc

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: MIT

min_ansible_version: 2.7

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

# Optionally specify the branch Galaxy will use when accessing the GitHub
# repo for this role. During role install, if no tags are available,
# Galaxy will use this branch. During import Galaxy will access files on
# this branch. If Travis integration is configured, only notifications for this
# branch will be accepted. Otherwise, in all cases, the repo's default branch
# (usually master) will be used.
#github_branch:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
platforms:
- name: RedHat
versions:
- 7
- name: Amazon
- name: EL
versions:
- 7

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

+ 20
- 0
tasks/docker-compose.yml View File

@@ -0,0 +1,20 @@
---
- name: Check current docker-compose version.
command: docker-compose --version
register: docker_compose_current_version
changed_when: false
failed_when: false

- name: Delete existing docker-compose version if it's different.
file:
path: "{{ docker_compose_path }}"
state: absent
when: >
docker_compose_current_version.stdout is defined
and docker_compose_version not in docker_compose_current_version.stdout

- name: Install Docker Compose (if configured).
get_url:
url: https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-x86_64
dest: "{{ docker_compose_path }}"
mode: 0755

+ 7
- 0
tasks/docker-users.yml View File

@@ -0,0 +1,7 @@
---
- name: Ensure docker users are added to the docker group.
user:
name: "{{ item }}"
groups: docker
append: true
with_items: "{{ docker_users }}"

+ 27
- 0
tasks/main.yml View File

@@ -0,0 +1,27 @@
---
- include_tasks: setup-RedHat.yml
when:
- ansible_os_family == 'RedHat'
- ansible_distribution != "Amazon"

- include_tasks: setup-Amazon.yml
when:
- ansible_distribution == "Amazon"

- include_tasks: setup-Debian.yml
when: ansible_os_family == 'Debian'

- name: Ensure Docker is started and enabled at boot.
service:
name: docker
state: "{{ docker_service_state }}"
enabled: "{{ docker_service_enabled }}"

- name: Ensure handlers are notified now to avoid firewall conflicts.
meta: flush_handlers

- include_tasks: docker-compose.yml
when: docker_install_compose

- include_tasks: docker-users.yml
when: docker_users

+ 6
- 0
tasks/setup-Amazon.yml View File

@@ -0,0 +1,6 @@
---
- name: "Install Docker."
package:
name: "docker"
state: "present"
notify: restart docker

+ 46
- 0
tasks/setup-Debian.yml View File

@@ -0,0 +1,46 @@
---
- name: Ensure old versions of Docker are not installed.
package:
name:
- docker
- docker-engine
state: absent

- name: Ensure dependencies are installed.
apt:
name:
- apt-transport-https
- ca-certificates
state: present

- name: Add Docker apt key.
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
id: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88
state: present
register: add_repository_key
ignore_errors: "{{ docker_apt_ignore_key_error }}"

- name: Ensure curl is present (on older systems without SNI).
package: name=curl state=present
when: add_repository_key is failed

- name: Add Docker apt key (alternative for older systems without SNI).
shell: |
set -o pipefail
curl -sSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
args:
warn: false
when: add_repository_key is failed

- name: Add Docker repository.
apt_repository:
repo: "{{ docker_apt_repository }}"
state: present
update_cache: true

- name: Install Docker.
package:
name: "{{ docker_package }}"
state: "{{ docker_package_state }}"
notify: restart docker

+ 58
- 0
tasks/setup-RedHat.yml View File

@@ -0,0 +1,58 @@
---
- name: Ensure old versions of Docker are not installed.
package:
name:
- docker
- docker-common
- docker-engine
state: absent

- name: Add Docker GPG key.
rpm_key:
key: https://download.docker.com/linux/centos/gpg
state: present

- name: Add Docker repository.
get_url:
url: "{{ docker_yum_repo_url }}"
dest: '/etc/yum.repos.d/docker-{{ docker_edition }}.repo'
owner: root
group: root
mode: 0644

- name: Configure Docker Edge repo.
ini_file:
dest: '/etc/yum.repos.d/docker-{{ docker_edition }}.repo'
section: 'docker-{{ docker_edition }}-edge'
option: enabled
value: '{{ docker_yum_repo_enable_edge }}'

- name: Configure Docker Test repo.
ini_file:
dest: '/etc/yum.repos.d/docker-{{ docker_edition }}.repo'
section: 'docker-{{ docker_edition }}-test'
option: enabled
value: '{{ docker_yum_repo_enable_test }}'

- name: "Find extra repos"
shell: "set -o pipefail; yum repolist all | egrep -e '^rhui-REGION-rhel-server-extras' -e '^rhel-7-server-extras-rpms' | cut -d'/' -f1"
args:
warn: no
register: "redhat_extrarepo"
changed_when: False
when: ansible_distribution == "RedHat"

- name: Install Docker.
package:
name: "{{ docker_package }}"
state: "{{ docker_package_state }}"
notify: restart docker
when: ansible_distribution != "RedHat"

- name: Install Docker.
yum:
name: "{{ docker_package }}"
state: "{{ docker_package_state }}"
enablerepo: "{{ redhat_extrarepo.stdout }}"
notify: restart docker
when: ansible_distribution == "RedHat"

+ 7
- 0
test/integration/default/main.rb View File

@@ -0,0 +1,7 @@
control "ansible-role-docker - #{os.name} #{os.release} - 01" do
impact 1.0
title 'Ansible role docker'
describe directory('/') do
it { should exist }
end
end

+ 5
- 0
tests/test.yml View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- ansible-role-docker

+ 2
- 0
vars/main.yml View File

@@ -0,0 +1,2 @@
---
# vars file for ansible-role-docker

Loading…
Cancel
Save