If people set options in `docker_daemon_options` (e.g. `{'ipv6': false}`), the role will create the `/etc/docker/daemon.json` file and populate it with the options.
Later on, if people stop setting *all of these* options, the file used to remain in place (containing the old options) and cause trouble. This is unexpected.
If the Docker installation is managed by this role and the `/etc/docker/daemon.json` file is managed by it, it should also take care to:
- either delete the file when it's no longer necessary
- or populate it with empty options if that is what `docker_daemon_options` contains
Deleting the file instead of putting `{}` in it seems like the cleaner approach.
There's a chance that people would like to manage options in `/etc/docker/daemon.json` by themselves (without Ansible) and this new behavior when `docker_daemon_options` is empty, but this runs against having a managed Docker installation via Ansible.
This patch only deletes the `/etc/docker/daemon.json` file.
We could possibly delete the `/etc/docker` directory too, but it's more tricky to delete it only when it's empty. In some cases, the directory may contain other files and invoking the `file` module with `state: absent` will delete everything recursively, which is undesirable.
This patch ensures that the correct filename is specified based on the distribution. Observed this behaviour on a Debian system, the old file was not removed due to it being hardcoded to ubuntu instead.
As described in https://github.com/ansible/ansible/issues/65687, get_url
only partially supports check_mode: "the changed status will reflect
comparison to an empty source file".
Before this change, executing this code, with the key already being in
place on the target system, would report "OK", while check_mode would
report "changed".
Due to this change, both now either report "OK" or "changed", depending
on the state of the target system.
Why:
Without this modification, we can't use docker with docker_users in same
playbook than the one which install docker.
How:
Check that docker_users are set and not in docker group before include
docker-users.yml. In docker-users.yml we call reset_connection from
ansible.builtin.meta collection after docker-users are added to docker
group.
Manual success tests:
* Try to install docker with only one user in docker-users and not in
docker group => docker-users.yml include
* Try to install docker with only one user in docker-users but the user
is in docker group => docker-users.yml not include
* Try to install docker with 2 users in docker-users, one user in docker
group and the second not => docker-users.yml include
* Try to install docker with 2 users in docker-users, both are in docker
group => docker-users.yml not include
* Try to install docker with 2 users in docker-users, both are not in
docker group => docker-users.yml include
- Docker no longer lists Debian 9 and Ubuntu 16.04 LTS under "OS requirements" and there are also no molecule tests for Ubuntu 16.04
- Added Ubuntu 22.04 LTS while on it
Not all package install handlers implement the `allow_downgrade` option.
For example, using Ansible >= 2.12 on Arch Linux would croak like:
Unsupported parameters for (ansible.legacy.pacman) module: allow_downgrade.
For the "package" task, add "allow_downgrade: true" to support this
scenario.
Because this option is only available starting with `ansible-core>=2.12`
for apt-based systems, we need conditional dispatching here.
yaml: truthy value should be one of [false, true] (truthy)
roles/geerlingguy.docker/tasks/docker-compose.yml:5
Fixesgeerlingguy/ansible-role-docker#325
# Configuration for probot-stale - https://github.com/probot/stale
---
# Number of days of inactivity before an Issue or Pull Request becomes stale
daysUntilStale:90
# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
daysUntilClose:30
# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled)
onlyLabels:[]
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
exemptLabels:
- pinned
- security
- planned
# Set to true to ignore issues in a project (defaults to false)
exemptProjects:false
# Set to true to ignore issues in a milestone (defaults to false)
exemptMilestones:false
# Set to true to ignore issues with an assignee (defaults to false)
exemptAssignees:false
# Label to use when marking as stale
staleLabel:stale
# Limit the number of actions per hour, from 1-30. Default is 30
limitPerRun:30
pulls:
markComment:|-
This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the PR will be closed in another 30 days. Thank you for your contribution!
Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark pull requests as stale.
unmarkComment:>-
This pull request is no longer marked for closure.
closeComment:>-
This pull request has been closed due to inactivity. If you feel this is in error, please reopen the pull request or file a new PR with the relevant details.
issues:
markComment:|-
This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!
Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale.
unmarkComment:>-
This issue is no longer marked for closure.
closeComment:>-
This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.
This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!
Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale.
close-issue-message:|
This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.
stale-pr-message:|
This pr has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!
Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale.
close-pr-message:|
This pr has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.
An Ansible Role that installs [Docker](https://www.docker.com) on Linux.
@ -12,54 +12,125 @@ None.
Available variables are listed below, along with default values (see `defaults/main.yml`):
# Edition can be one of: 'ce' (Community Edition) or 'ee' (Enterprise Edition).
docker_edition: 'ce'
docker_package: "docker-{{ docker_edition }}"
docker_package_state: present
```yaml
# Edition can be one of: 'ce' (Community Edition) or 'ee' (Enterprise Edition).
docker_edition: 'ce'
docker_packages:
- "docker-{{ docker_edition }}"
- "docker-{{ docker_edition }}-cli"
- "docker-{{ docker_edition }}-rootless-extras"
docker_packages_state: present
```
The `docker_edition` should be either `ce` (Community Edition) or `ee` (Enterprise Edition). You can also specify a specific version of Docker to install using the distribution-specific format: Red Hat/CentOS: `docker-{{ docker_edition }}-<VERSION>`; Debian/Ubuntu: `docker-{{ docker_edition }}=<VERSION>`.
The `docker_edition` should be either `ce` (Community Edition) or `ee` (Enterprise Edition).
You can also specify a specific version of Docker to install using the distribution-specific format:
Red Hat/CentOS: `docker-{{ docker_edition }}-<VERSION>` (Note: you have to add this to all packages);
Debian/Ubuntu: `docker-{{ docker_edition }}=<VERSION>` (Note: you have to add this to all packages).
You can control whether the package is installed, uninstalled, or at the latest version by setting `docker_package_state` to `present`, `absent`, or `latest`, respectively. Note that the Docker daemon will be automatically restarted if the Docker package is updated. This is a side effect of flushing all handlers (running any of the handlers that have been notified by this and any other role up to this point in the play).
You can control whether the package is installed, uninstalled, or at the latest version by setting `docker_packages_state` to `present`, `absent`, or `latest`, respectively. Note that the Docker daemon will be automatically restarted if the Docker package is updated. This is a side effect of flushing all handlers (running any of the handlers that have been notified by this and any other role up to this point in the play).
docker_service_state: started
docker_service_enabled: true
docker_restart_handler_state: restarted
```yaml
docker_obsolete_packages:
- docker
- docker.io
- docker-engine
- docker-doc
- docker-compose
- docker-compose-v2
- podman-docker
- containerd
- runc
```
Variables to control the state of the `docker` service, and whether it should start on boot. If you're installing Docker inside a Docker container without systemd or sysvinit, you should set these to `stopped` and set the enabled variable to `no`.
`docker_obsolete_packages` for different os-family:
A list of packages to be uninstalled prior to running this role. See [Docker's installation instructions](https://docs.docker.com/engine/install/debian/#uninstall-old-versions) for an up-to-date list of old packages that should be removed.
```yaml
docker_service_manage: true
docker_service_state: started
docker_service_enabled: true
docker_restart_handler_state: restarted
```
Variables to control the state of the `docker` service, and whether it should start on boot. If you're installing Docker inside a Docker container without systemd or sysvinit, you should set `docker_service_manage` to `false`.
```yaml
docker_install_compose_plugin: true
docker_compose_package: docker-compose-plugin
docker_compose_package_state: present
```
Docker Compose Plugin installation options. These differ from the below in that docker-compose is installed as a docker plugin (and used with `docker compose`) instead of a standalone binary.
(Used only for Debian/Ubuntu.) You can switch the channel to `edge` if you want to use the Edge release.
Controls whether this role will add the official Docker repository. Set to `false` if you want to use the default docker packages for your system or manage the package repository on your own.
(Used only for Debian/Ubuntu.) You can switch the channel to `nightly` if you want to use the Nightly release.
You can change `docker_apt_gpg_key` to a different url if you are behind a firewall or provide a trustworthy mirror.
Usually in combination with changing `docker_apt_repository` as well.
Usually in combination with changing `docker_apt_repository` as well.`docker_apt_filename` controls the name of the source list file created in `sources.list.d`. If you are upgrading from an older (<7.0.0)versionofthisrole,youshouldchangethistothenameoftheexistingfile(e.g.`download_docker_com_linux_debian`onDebian)toavoidconflictinglists.
(Used only for RedHat/CentOS.) You can enable the Edge or Test repo by setting the respective vars to `1`.
(Used only for RedHat/CentOS.) You can enable the Nightly or Test repo by setting the respective vars to `1`.
You can change `docker_yum_gpg_key` to a different url if you are behind a firewall or provide a trustworthy mirror.
Usually in combination with changing `docker_yum_repository` as well.
docker_users:
- user1
- user2
```yaml
docker_users:
- user1
- user2
```
A list of system users to be added to the `docker` group (so they can use Docker on the server).
```yaml
docker_daemon_options:
storage-driver: "overlay2"
log-opts:
max-size: "100m"
```
Custom `dockerd` options can be configured through this dictionary representing the json file `/etc/docker/daemon.json`.
## Use with Ansible (and `docker` Python library)
Many users of this role wish to also use Ansible to then _build_ Docker images and manage Docker containers on the server where Docker is installed. In this case, you can easily add in the `docker` Python library using the `geerlingguy.pip` role:
@ -92,6 +163,12 @@ None.
MIT / BSD
## Sponsors
* [We Manage](https://we-manage.de): Helping start-ups and grown-ups scaling their infrastructure in a sustainable way.
The above sponsor(s) are supporting Jeff Geerling on [GitHub Sponsors](https://github.com/sponsors/geerlingguy). You can sponsor Jeff's work too, to help him continue improving these Ansible open source projects!
## Author Information
This role was created in 2017 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).
when:"ansible_version.full is version_compare('2.12', '>=') and ansible_os_family in ['RedHat', 'Debian']"
- name:Install docker-compose plugin.
package:
name:"{{ docker_compose_package }}"
state:"{{ docker_compose_package_state }}"
notify:restart docker
ignore_errors:"{{ ansible_check_mode }}"
when:"docker_install_compose_plugin | bool == true and (ansible_version.full is version_compare('2.12', '<') or ansible_os_family not in ['RedHat', 'Debian'])"
when:"docker_install_compose_plugin | bool == true and ansible_version.full is version_compare('2.12', '>=') and ansible_os_family in ['RedHat', 'Debian']"
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.