-
Notifications
You must be signed in to change notification settings - Fork 14
replace ansible docker_compose module with command #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replace ansible docker_compose module with command #136
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@niorg thanks again for submitting a PR!, and sorry it took us this long to finally review it.
If you have some time and would like to do the adjustments yourself, please do so. Once that's in place, I'll merge the PR.
If you don't have the time, I'll merge it and adjust it.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would change it to be
# install docker
- name: Install required system packages
apt: name={{ item }} state=latest update_cache=yes
loop:
- 'apt-transport-https'
- 'ca-certificates'
- 'curl'
- 'software-properties-common'
- 'python3-pip'
- 'virtualenv'
- 'python3-setuptools'
- name: Create the keyrings folder
file:
path: /etc/apt/keyrings
state: directory
mode: '0755'
- name: Add Docker GPG apt Key
get_url:
url: https://download.docker.com/linux/ubuntu/gpg
dest: /etc/apt/keyrings/docker.asc
- name: Fix Docker key permissions
file:
path: /etc/apt/keyrings/docker.asc
mode: '0666'
- name: Get APT package architecture
command: dpkg --print-architecture
register: dpkg_arch
- name: Add Docker repo
apt_repository:
repo: "deb [arch={{ dpkg_arch.stdout }} signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
state: present
- name: Update apt repositories
apt:
update_cache: yes
- name: Install Docker and Docker Compose
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
- name: Install Docker Module for Python
pip:
name:
- docker
- docker-compose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- name: Install Docker and Docker Compose
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
You only need to install docker-ce package, the other modules will come along as a dependency.
- name: Install Docker Module for Python
pip:
name:
- docker
- docker-compose
docker-compose python module is no longer used so no need to install.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Just in case and to leave it documented, confirmed this in Ubuntu 18/20/22.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docker flag to remove orphans doesn't accept values. So another approach would be this one.
- name: Start docker-compose with remove orphans
ansible.builtin.command: "docker compose --project-directory {{ app_install_root }}/{{ app_repo_name }} up --detach --build --force-recreate --remove-orphans"
register: output
when: docker_remove_orphans | bool
- name: Start docker-compose without remove orphans
ansible.builtin.command: "docker compose --project-directory {{ app_install_root }}/{{ app_repo_name }} up --detach --build --force-recreate"
register: output
when: not ( docker_remove_orphans | bool )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What makes you say that it doesn't accept values? My version 2.21.0 most certainly does work that way. Tested on MacOS and Ubuntu.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though what you say is true about the flag, it doesn't exist in any official docker documentation. (Or at least I couldn't find any)
So, just to follow the standard documented way, would keep it this way.
Fixes #135