Skip to content

Instantly share code, notes, and snippets.

@michaelact
Last active January 3, 2022 12:08
Show Gist options
  • Save michaelact/7a21871c11b561dc2b78e569da819557 to your computer and use it in GitHub Desktop.
Save michaelact/7a21871c11b561dc2b78e569da819557 to your computer and use it in GitHub Desktop.
Example of the documentation produced from https://github.com/michaelact/Ansibila.go

Ansible Role: docker

Docker for Linux.

Platforms

Name Version
EL [7 8]
Fedora [all]
Debian [stretch buster bullseye]
Ubuntu [xenial bionic focal]

Modules

Name URL
service https://docs.ansible.com/ansible/latest/collections/ansible/builtin/service_module.html
command https://docs.ansible.com/ansible/latest/collections/ansible/builtin/command_module.html
file https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html
get_url https://docs.ansible.com/ansible/latest/collections/ansible/builtin/get_url_module.html
user https://docs.ansible.com/ansible/latest/collections/ansible/builtin/user_module.html
package https://docs.ansible.com/ansible/latest/collections/ansible/builtin/package_module.html
file https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html
copy https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html
service https://docs.ansible.com/ansible/latest/collections/ansible/builtin/service_module.html
meta https://docs.ansible.com/ansible/latest/collections/ansible/builtin/meta_module.html
package https://docs.ansible.com/ansible/latest/collections/ansible/builtin/package_module.html
apt https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_module.html
shell https://docs.ansible.com/ansible/latest/collections/ansible/builtin/shell_module.html
package https://docs.ansible.com/ansible/latest/collections/ansible/builtin/package_module.html
rpm_key https://docs.ansible.com/ansible/latest/collections/ansible/builtin/rpm_key_module.html
get_url https://docs.ansible.com/ansible/latest/collections/ansible/builtin/get_url_module.html
ini_file https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ini_file_module.html
block https://docs.ansible.com/ansible/latest/collections/ansible/builtin/block_module.html

Variables

Name Description Type Default Required
docker_compose_version Docker Compose Version str 1.26.0 no
docker_service_enabled Enable Docker Engine Service in Startup? bool true no
docker_compose_url Download URL of Docker Compose str https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-x86_64 no
docker_yum_repo_enable_test Enable test Docker Release State? int 0 no
docker_users Users Who Will be Added to Docker Group list [] no
docker_daemon_options Docker Daemon Options dict map[] no
docker_repo_url Docker Repository URL str https://download.docker.com/linux no
docker_apt_release_channel Release Status to Install str stable no
docker_apt_repository Repository line to put in /etc/apt/sources.list str deb [arch={{ docker_apt_arch }}] {{ docker_repo_url }}/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} {{ docker_apt_release_channel }} no
docker_yum_repo_url Docker Repository URL str {{ docker_repo_url }}/{{ (ansible_distribution == 'Fedora') | ternary('fedora','centos') }}/docker-{{ docker_edition }}.repo no
docker_apt_gpg_key Docker Repository key URL str {{ docker_repo_url }}/{{ ansible_distribution | lower }}/gpg no
docker_package_state Install Docker Engine? str present no
docker_install_compose Install Docker Compose? bool true no
docker_yum_repo_enable_nightly Enable nightly Docker Release State? int 0 no
docker_edition Docker Edition str ce no
docker_compose_path Path to Install Docker Compose Binary str /usr/local/bin/docker-compose no
docker_restart_handler_state Restart the Service after installed? str restarted no
docker_apt_arch Host Instance Architecture str amd64 no
docker_yum_gpg_key Docker Repository key URL str {{ docker_repo_url }}/centos/gpg no
docker_package Full Package Name str docker-{{ docker_edition }} no
docker_apt_ignore_key_error Ignore even getting error while importing docker repository key? bool true no
docker_service_state started no

Example Playbook

---
- name: Converge
  hosts: all
  become: true

  pre_tasks:
    - name: Update apt cache.
      apt: update_cache=yes cache_valid_time=600
      when: ansible_os_family == 'Debian'

    - name: Wait for systemd to complete initialization.  # noqa 303
      command: systemctl is-system-running
      register: systemctl_status
      until: >
        'running' in systemctl_status.stdout or
        'degraded' in systemctl_status.stdout
      retries: 30
      delay: 5
      when: ansible_service_mgr == 'systemd'
      changed_when: false
      failed_when: systemctl_status.rc > 1

  roles:
    - role: geerlingguy.docker

Notes

  • Encrypt all confidential variable on vault.

LICENSE

license (BSD, MIT)

Author Information

This role was created by Midwestern Mac, LLC geerlingguy Team.

TMPL_DIR ?= .
.PHONY: prepare
prepare: ## Preparing Ansibila Requirements
@ $(MAKE) --no-print-directory log-$@
mkdir -p ${ROLE_DIR}/molecule/default
mkdir -p ${ROLE_DIR}/meta
touch $(ROLE_DIR)/variables.yml
touch $(ROLE_DIR)/molecule/default/playbook.yml
touch $(ROLE_DIR)/meta/main.yml
.PHONY: check
check: prepare ## Check Attributes
@ $(MAKE) --no-print-directory log-$@
ansibila \
--dirpath $(ROLE_DIR) \
--varfile variables.yml \
--tmplpath $(TMPL_DIR) \
check
.PHONY: generate
generate: prepare ## Generate Documentation in Single Role Directory
@ $(MAKE) --no-print-directory log-$@
ansibila \
--dirpath $(ROLE_DIR) \
--varfile variables.yml \
--tmplpath $(TMPL_DIR) \
markdown table > $(ROLE_DIR)/README.md
########################################################################
## Self-Documenting Makefile Help ##
## https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html ##
########################################################################
########
##@ Help
.PHONY: help
help: ## Display this help
@awk \
-v "col=\033[36m" -v "nocol=\033[0m" \
' \
BEGIN { \
FS = ":.*##" ; \
printf "Usage:\n make %s<target>%s\n", col, nocol \
} \
/^[a-zA-Z_-]+:.*?##/ { \
printf " %s%-12s%s %s\n", col, $$1, nocol, $$2 \
} \
/^##@/ { \
printf "\n%s%s%s\n", nocol, substr($$0, 5), nocol \
} \
' $(MAKEFILE_LIST)
log-%:
@grep -h -E '^$*:.*?## .*$$' $(MAKEFILE_LIST) | \
awk \
'BEGIN { \
FS = ":.*?## " \
}; \
{ \
printf "\033[36m==> %s\033[0m\n", $$2 \
}'
<!-- BEGIN_ANSIBILA.GO -->
{{ if not .Metadata.GalaxyInfo.RoleName }}
# Ansible Role
{{- if not .Metadata.GalaxyInfo.Description }}
This role has a description.
{{ else }}
{{ .Metadata.GalaxyInfo.Description -}}
{{ end }}
{{ else }}
# Ansible Role: {{ .Metadata.GalaxyInfo.RoleName }}
{{- if not .Metadata.GalaxyInfo.Description }}
This role has a description.
{{ else }}
{{ .Metadata.GalaxyInfo.Description -}}
{{ end }}
{{ end }}
{{ if not .Metadata.GalaxyInfo.Platforms }}
{{- indent 0 "#" }} Platforms
General Platform.
{{ else }}
{{- indent 0 "#" }} Platforms
| Name | Version |
|------|:-------:|
{{- range $i, $platform := .Metadata.GalaxyInfo.Platforms }}
| {{ $platform.Name }} | {{ $platform.Versions }} |
{{- end }}
{{ end }}
{{ if not .Modules }}
{{- indent 0 "#" }} Modules
No Modules.
{{ else }}
{{- indent 0 "#" }} Modules
| Name | URL |
|------|:---:|
{{- range $i, $module := .Modules }}
| {{ $module.Name }} | {{ $module.FullURL }} |
{{- end }}
{{ end }}
{{ if not .Variables }}
{{- indent 0 "#" }} Variables
No Variables.
{{ else }}
{{- indent 0 "#" }} Variables
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
{{- range $i, $variable := .Variables }}
| {{ anchorNameMarkdown "input" $variable.Name }} | {{ $variable.Description }} | {{ $variable.Type }} | {{ sanitize (tostring $variable.Value) }} | {{ ternary $variable.Required "yes" "no" }} |
{{- end }}
{{ end }}
{{ if not .Playbook }}
{{- indent 0 "#" }} Example Playbook
No Example Playbook.
{{ else }}
{{- indent 0 "#" }} Example Playbook
```
{{- range $i, $line := .Playbook }}
{{ $line.Value }}
{{- end }}
```
{{ end }}
## Notes
- Encrypt all confidential variable on vault.
{{ if not .Metadata.GalaxyInfo.License }}
{{- indent 0 "#" }} LICENSE
No License.
{{ else }}
{{- indent 0 "#" }} LICENSE
{{ .Metadata.GalaxyInfo.License }}
{{ end }}
{{ if not .Metadata.GalaxyInfo.Author }}
{{- indent 0 "#" }} Author Information
This role has an author.
{{ else }}
{{- indent 0 "#" }} Author Information
This role was created by {{ .Metadata.GalaxyInfo.Company }} {{ .Metadata.GalaxyInfo.Author }} Team.
{{ end }}
<!-- END_ANSIBILA.GO -->
# Manual Declaration
docker_restart_handler_state:
type: str
description: Restart the Service after installed?
docker_apt_gpg_key:
type: str
description: Docker Repository key URL
docker_users:
type: list
description: Users Who Will be Added to Docker Group
docker_daemon_options:
type: dict
description: Docker Daemon Options
docker_package_state:
type: str
description: Install Docker Engine?
docker_install_compose:
type: bool
description: Install Docker Compose?
docker_compose_version:
type: str
description: Docker Compose Version
docker_repo_url:
type: str
description: Docker Repository URL
docker_apt_arch:
type: str
description: Host Instance Architecture
docker_yum_repo_enable_nightly:
type: int
description: Enable nightly Docker Release State?
docker_service_enabled:
type: bool
description: Enable Docker Engine Service in Startup?
docker_compose_url:
type: str
description: Download URL of Docker Compose
docker_yum_repo_enable_test:
type: int
description: Enable test Docker Release State?
docker_yum_gpg_key:
type: str
description: Docker Repository key URL
docker_edition:
type: str
description: Docker Edition
docker_package:
type: str
description: Full Package Name
docker_compose_path:
type: str
description: Path to Install Docker Compose Binary
docker_apt_release_channel:
type: str
description: Release Status to Install
docker_apt_repository:
type: str
description: Repository line to put in /etc/apt/sources.list
docker_apt_ignore_key_error:
type: bool
description: Ignore even getting error while importing docker repository key?
docker_yum_repo_url:
type: str
description: Docker Repository URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment