Last active
March 19, 2023 23:34
-
-
Save jasonbronson/45d21ec3429b2d5c6da58dac4269a312 to your computer and use it in GitHub Desktop.
install_debian11_docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: all | |
become: true | |
tasks: | |
- name: Modify SSHD config for public key auth and root password login | |
lineinfile: | |
path: /etc/ssh/sshd_config | |
regexp: '^#?PasswordAuthentication' | |
line: 'PasswordAuthentication yes' | |
state: present | |
notify: | |
- restart sshd | |
- name: Enable public key auth in SSHD config | |
lineinfile: | |
path: /etc/ssh/sshd_config | |
regexp: '^#?PubkeyAuthentication' | |
line: 'PubkeyAuthentication yes' | |
state: present | |
- name: Update package cache | |
apt: | |
update_cache: yes | |
- name: Install required packages | |
apt: | |
name: | |
- vim | |
- ca-certificates | |
- curl | |
- gnupg | |
- lsb-release | |
state: present | |
- name: Create /etc/apt/keyrings directory | |
file: | |
path: /etc/apt/keyrings | |
state: directory | |
mode: 0755 | |
- name: Add Docker GPG key | |
command: curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg | |
- name: Add Docker APT repository | |
apt_repository: | |
repo: 'deb [arch={{ dpkg_architecture }} signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian {{ lsb_release_codename }} stable' | |
state: present | |
filename: docker.list | |
update_cache: yes | |
- name: Install Docker | |
apt: | |
name: | |
- docker-ce | |
- docker-ce-cli | |
- containerd.io | |
- docker-buildx-plugin | |
- docker-compose-plugin | |
state: present | |
- name: Create Portainer data volume | |
docker_volume: | |
name: portainer_data | |
state: present | |
- name: Run Portainer container | |
docker_container: | |
name: portainer | |
image: portainer/portainer-ce:latest | |
state: started | |
restart_policy: always | |
ports: | |
- "8000:8000" | |
- "9443:9443" | |
volumes: | |
- /var/run/docker.sock:/var/run/docker.sock | |
- portainer_data:/data | |
- name: Configure Docker to use /docker directory | |
lineinfile: | |
path: /lib/systemd/system/docker.service | |
regexp: '^ExecStart=/usr/bin/dockerd' | |
line: 'ExecStart=/usr/bin/dockerd -g /docker' | |
state: present | |
backup: yes | |
notify: | |
- restart docker | |
handlers: | |
- name: Restart SSHD service | |
systemd: | |
name: sshd | |
state: restarted | |
- name: Restart Docker service | |
systemd: | |
name: docker | |
state: restarted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment