Skip to content

Commit

Permalink
fix: Use a variable to control uninstall behavior instead of tags (#253)
Browse files Browse the repository at this point in the history
Co-authored-by: VoidQuark <[email protected]>
  • Loading branch information
dobbi84 and voidquark authored Aug 9, 2024
1 parent c0dd9d6 commit 02e1143
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 37 deletions.
11 changes: 9 additions & 2 deletions roles/loki/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The Ansible Loki Role allows you to effortlessly deploy and manage [Loki](https:

**🔑 Key Features**
- **📦 Out-of-the-box Deployment**: Get Loki up and running quickly with default configurations.
- **🧹 Effortless Uninstall**: Easily remove Loki from your system using the "loki_uninstall" tag.
- **🧹 Effortless Uninstall**: Easily remove Loki from your system setting the "loki_uninstall" variable.
- **🔔 Example Alerting Rules**: Benefit from the included sample Ruler configuration. Utilize the provided example alerting rules as a reference guide for structuring your own rules effectively.

## Table of Content
Expand All @@ -32,8 +32,15 @@ The Ansible Loki Role allows you to effortlessly deploy and manage [Loki](https:
```yaml
loki_version: "latest"
```
The version of Loki to download and deploy. Supported standard version "3.0.0" format or "latest".
```yaml
loki_uninstall: "false"
```
If set to `true` will perfom uninstall instead of deployment.

```yaml
loki_http_listen_port: 3100
```
Expand Down Expand Up @@ -226,7 +233,7 @@ Below variables allow you to extend Loki configuration to fit your needs. Always
ansible-playbook -i inventory/hosts playbook/function_loki_play.yml
# Uninstall
ansible-playbook -i inventory/hosts playbook/function_loki_play.yml -t loki_uninstall
ansible-playbook -i inventory/hosts playbook/function_loki_play.yml -e "loki_uninstall=true"
```

## License
Expand Down
1 change: 1 addition & 0 deletions roles/loki/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
# defaults file for loki
loki_version: "latest"
loki_uninstall: false
loki_http_listen_port: 3100
loki_http_listen_address: "0.0.0.0"
loki_expose_port: false
Expand Down
12 changes: 2 additions & 10 deletions roles/loki/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,9 @@
- name: Deploy Loki service
ansible.builtin.include_tasks:
file: "deploy.yml"
apply:
tags: loki_deploy
tags: loki_deploy
when: not loki_uninstall

- name: Uninstall Loki service
ansible.builtin.include_tasks:
file: "uninstall.yml"
apply:
tags:
- loki_uninstall
- never
tags:
- loki_uninstall
- never
when: loki_uninstall
7 changes: 4 additions & 3 deletions roles/mimir/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ docker run -d \
### Testing the changes
To test the changes in a role run:
```sh
molecule converge
## example: molecule converge
molecule converge
## example: molecule converge
```
When Ansible has succesfully ran, you can run assertions against your infrastructure using.
```sh
molecule verify
molecule verify
## example: `molecule verify`
```

Expand All @@ -65,6 +65,7 @@ You can also run commands like `molecule destroy`, `molecule prepare`, and `mole
| Name | Type | Default | Description |
|---|---|---|---|
mimir_working_path|str|/usr/share/mimir|Used to specify the directory path where Mimir, a component of the Grafana Agent, stores its working files and temporary data.|
mimir_uninstall|bool|false|If set to `true` will perfom uninstall instead of deployment.|
mimir_ruler_alert_path|str|/data/ruler|Used to specify the directory path where the Mimir ruler component of the Grafana Agent stores its alert files.|
mimir_http_listen_port|str|8080|Used to specify the port number on which the Mimir component of the Grafana Agent listens for incoming HTTP requests.|
mimir_http_listen_address|str|0.0.0.0|Used to specify the network address on which the Mimir component of the Grafana Agent listens for incoming HTTP requests.|
Expand Down
1 change: 1 addition & 0 deletions roles/mimir/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
# defaults file for mimir
mimir_version: "latest"
mimir_uninstall: false
__mimir_arch: "{{ arch_mapping[ansible_architecture] | default('amd64') }}"
mimir_download_url_rpm: "https://github.com/grafana/mimir/releases/download/{{ mimir_version }}/{{ mimir_version }}_{{ __mimir_arch }}.rpm"
mimir_download_url_deb: "https://github.com/grafana/mimir/releases/download/{{ mimir_version }}/{{ mimir_version }}_{{ __mimir_arch }}.deb"
Expand Down
12 changes: 2 additions & 10 deletions roles/mimir/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
- name: Deploy Mimir service
ansible.builtin.include_tasks:
file: "deploy.yml"
apply:
tags: mimir_deploy
tags: mimir_deploy
when: not mimir_uninstall

- name: Uninstall Mimir service
ansible.builtin.include_tasks:
file: "uninstall.yml"
apply:
tags:
- mimir_uninstall
- never
tags:
- mimir_uninstall
- never
when: mimir_uninstall
10 changes: 8 additions & 2 deletions roles/promtail/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This role is tailored for operating systems such as **RedHat**, **Rocky Linux**,

**🔑 Key Features**
- **⚡ Root-less/Root runtime**: By default, Promtail operates in root-less mode, utilizing ACL (Access Control List) to securely access logs without requiring root permissions. You have the option to configure root mode if necessary.
- **🧹 Effortless Uninstall**: Easily remove Promtail from your system using the "promtail_uninstall" tag.
- **🧹 Effortless Uninstall**: Easily remove Promtail from your system setting the "promtail_uninstall" variable.

📢 **[Check the blog post](https://voidquark.com/blog/rootless-promtail-with-ansible/)** 📝 **Learn more about root-less mode.**

Expand All @@ -28,6 +28,12 @@ promtail_version: "latest"
```
The version of Promtail to download and deploy. Supported standard version "3.0.0" format or "latest".
```yaml
promtail_uninstall: "false"
```
If set to `true` will perfom uninstall instead of deployment.

```yaml
promtail_http_listen_port: 9080
```
Expand Down Expand Up @@ -152,7 +158,7 @@ No Dependencies
ansible-playbook function_promtail_play.yml
# Uninstall Promtail
ansible-playbook function_promtail_play.yml -t promtail_uninstall
ansible-playbook function_promtail_play.yml -e "promtail_uninstall=true"
```

## License
Expand Down
1 change: 1 addition & 0 deletions roles/promtail/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
# defaults file for promtail
promtail_version: "latest"
promtail_uninstall: false
promtail_http_listen_port: 9080
promtail_http_listen_address: "0.0.0.0"
promtail_expose_port: false
Expand Down
12 changes: 2 additions & 10 deletions roles/promtail/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,9 @@
- name: Deploy Promtail service
ansible.builtin.include_tasks:
file: "deploy.yml"
apply:
tags: promtail_deploy
tags: promtail_deploy
when: not promtail_uninstall

- name: Uninstall Promtail service
ansible.builtin.include_tasks:
file: "uninstall.yml"
apply:
tags:
- promtail_uninstall
- never
tags:
- promtail_uninstall
- never
when: promtail_uninstall

0 comments on commit 02e1143

Please sign in to comment.