Skip to content

Commit

Permalink
[NEW] added Portainer playbook
Browse files Browse the repository at this point in the history
  • Loading branch information
ismoilovdevml committed Sep 28, 2024
1 parent 257ef38 commit c556b36
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Ansible/portainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Portainer Installation 🚀

This repository contains Ansible playbooks for installing and cleaning up Portainer Community Edition (CE) and Business Edition (BE). These playbooks manage Docker containers and images.

## 🛠 Installation Playbooks

### 📥 `install_portainer_ce.yml`
This playbook installs Portainer CE (Community Edition):
- Creates a Docker volume.
- Runs the Portainer container.
- Displays the list of Docker containers.

**Usage:**
```bash
ansible-playbook -i inventory install_portainer_ce.yml
```

### 📥 `install_portainer_ee.yml`
This playbook installs Portainer EE (Interprice Edition):
- Creates a Docker volume.
- Runs the Portainer container.
- Displays the list of Docker containers.

**Usage:**
```bash
ansible-playbook -i inventory install_portainer_ee.yml
```

### 🧹 Cleanup Playbook
🗑️ `clean_portainer.yml`
This playbook cleans up Portainer CE and BE installations:

* Removes the Portainer container (if it exists).
* Removes the Docker volume (if it exists).
* Removes Portainer CE and BE Docker images (if they exist).
**Usage:**

```bash
ansible-playbook -i inventory clean_portainer.yml
```

### 🔍 Notes
* The playbooks check for the existence of containers, volumes, and images before attempting removal.
* Docker images are checked using the **2.21.2** tag for Portainer CE and EE.
43 changes: 43 additions & 0 deletions Ansible/portainer/clean_portainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
- name: Clean up Portainer installation
hosts: all
become: yes

tasks:
- name: Check if Portainer container exists
shell: docker ps -a --format '{{"{{.Names}}"}}' | grep -w portainer || true
register: portainer_exists
changed_when: false

- name: Remove Portainer container
command: docker rm -f portainer
when: portainer_exists.stdout != ""
ignore_errors: yes

- name: Check if Portainer volume exists
shell: docker volume ls --format '{{"{{.Name}}"}}' | grep -w portainer_data || true
register: volume_exists
changed_when: false

- name: Remove Portainer Docker volume
command: docker volume rm portainer_data
when: volume_exists.stdout != ""
ignore_errors: yes

- name: Check if Portainer CE image exists
shell: docker images --format '{{"{{.Repository}}:{{.Tag}}"}}' | grep -w 'portainer/portainer-ce:2.21.2' || true
register: ce_image_exists
changed_when: false

- name: Remove Portainer CE image
command: docker rmi portainer/portainer-ce:2.21.2
when: ce_image_exists.stdout != ""

- name: Check if Portainer BE image exists
shell: docker images --format '{{"{{.Repository}}:{{.Tag}}"}}' | grep -w 'portainer/portainer-ee:2.21.2' || true
register: be_image_exists
changed_when: false

- name: Remove Portainer BE image
command: docker rmi portainer/portainer-ee:2.21.2
when: be_image_exists.stdout != ""
19 changes: 19 additions & 0 deletions Ansible/portainer/install_portainer_ce.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Install Portainer Community Edition
hosts: portainer_ce
become: yes

tasks:
- name: Create Docker volume for Portainer data
command: docker volume create portainer_data

- name: Run Portainer CE container
command: docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:2.21.2

- name: Display Docker containers
command: docker ps
register: result

- name: Show Docker container output
debug:
var: result.stdout
19 changes: 19 additions & 0 deletions Ansible/portainer/install_portainer_ee.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Install Portainer Business Edition
hosts: portainer_ee
become: yes

tasks:
- name: Create Docker volume for Portainer data
command: docker volume create portainer_data

- name: Run Portainer BE container
command: docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ee:2.21.2

- name: Display Docker containers
command: docker ps
register: result

- name: Show Docker container output
debug:
var: result.stdout
11 changes: 11 additions & 0 deletions Ansible/portainer/inventory.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[portainer_ce]
; debian ansible_host=10.128.0.47 ansible_user=root
; ubuntu ansible_host=10.128.0.48 ansible_user=root
; rhel ansible_host=10.128.0.45 ansible_user=root
ubuntu ansible_host=206.189.226.65 ansible_user=root

[portainer_ee]
ubuntu ansible_host=206.189.226.65 ansible_user=root
; debian ansible_host=10.128.0.47 ansible_user=root
; ubuntu ansible_host=10.128.0.48 ansible_user=root
; rhel ansible_host=10.128.0.45 ansible_user=root

0 comments on commit c556b36

Please sign in to comment.