Skip to content

Commit

Permalink
major: used full qualified collection names
Browse files Browse the repository at this point in the history
  • Loading branch information
tboerger committed Feb 6, 2024
1 parent 92c6208 commit cff737e
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions/checkout@v4

- name: Role linting
uses: actionhippie/ansible-later@v2
uses: actionhippie/ansible-later@v3

testing:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
- name: Restart prometheus
systemd:
ansible.builtin.systemd:
name: prometheus
state: restarted
daemon_reload: True

- name: Restart prometheus-oauth2
systemd:
ansible.builtin.systemd:
name: prometheus-oauth2
state: restarted
daemon_reload: yes
Expand Down
9 changes: 9 additions & 0 deletions meta/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
collections:
- ansible.posix
- community.general
- community.docker

roles: []

...
41 changes: 36 additions & 5 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,48 @@
gather_facts: False

tasks:
- name: Stat apt dir
register: aptdir
ansible.builtin.stat:
path: /var/lib/apt

- name: Wait for aptlock
shell: while fuser /var/lib/apt/lists/lock >/dev/null 2>&1; do echo 'Waiting for apt list lock.' && sleep 10; done
when: aptdir.stat.exists
changed_when: False
ansible.builtin.shell:
cmd: while fuser /var/lib/apt/lists/lock >/dev/null 2>&1; do echo 'Waiting for apt list lock.' && sleep 10; done

- name: Update package cache
apt:
when: aptdir.stat.exists
ansible.builtin.apt:
update_cache: True

- name: Install gpg dependency
apt:
name: python3-gpg
- name: Install test dependencies
when: aptdir.stat.exists
loop:
- python3-gpg
- curl
ansible.builtin.apt:
name: "{{ item }}"
state: present

- name: Create man dirs
changed_when: False
loop:
- /usr/share/man/man1
- /usr/share/man/man2
- /usr/share/man/man3
- /usr/share/man/man4
- /usr/share/man/man5
- /usr/share/man/man6
- /usr/share/man/man7
- /usr/share/man/man8
- /usr/share/man/man9
ansible.builtin.file:
path: "{{ item }}"
owner: root
group: root
mode: u=rwx,g=rx,o=rx
state: directory

...
6 changes: 5 additions & 1 deletion molecule/requirements.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
collections: []
collections:
- ansible.posix
- community.general
- community.docker

roles: []

...
52 changes: 26 additions & 26 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- prometheus_installation == 'native'
loop:
- rsync
package:
ansible.builtin.package:
name: "{{ item }}"
state: present
tags:
Expand All @@ -13,7 +13,7 @@
- name: Create system group
when:
- prometheus_installation == 'native'
group:
ansible.builtin.group:
name: prometheus
system: True
state: present
Expand All @@ -23,11 +23,11 @@
- name: Create system user
when:
- prometheus_installation == 'native'
user:
ansible.builtin.user:
name: prometheus
group: prometheus
password: "!"
shell: /usr/sbin/nologin
ansible.builtin.shell: /usr/sbin/nologin
home: /var/lib/prometheus
create_home: False
system: True
Expand All @@ -37,7 +37,7 @@

- name: Create required directories
loop: "{{ prometheus_default_folders + prometheus_extra_folders }}"
file:
ansible.builtin.file:
path: "{{ item }}"
owner: "{{ 'prometheus' if prometheus_installation == 'native' else 'nobody' }}"
group: "{{ 'prometheus' if prometheus_installation == 'native' else 'nogroup' }}"
Expand All @@ -53,14 +53,14 @@
failed_when: False
changed_when: False
check_mode: False
shell: /usr/bin/prometheus --version 2>&1
ansible.builtin.shell: /usr/bin/prometheus --version 2>&1
tags:
- prometheus

- name: Fact version change
when:
- prometheus_installation == 'native'
set_fact:
ansible.builtin.set_fact:
prometheus_version_changed: "{{ prometheus_version_check.rc != 0 or (prometheus_version_check.stdout_lines is defined and prometheus_version not in prometheus_version_check.stdout_lines[0]) | bool }}"
tags:
- prometheus
Expand All @@ -71,7 +71,7 @@
- prometheus_version_changed
notify:
- Restart prometheus
unarchive:
ansible.builtin.unarchive:
src: "{{ prometheus_download }}"
dest: /usr/local/src
remote_src: True
Expand All @@ -88,7 +88,7 @@
notify:
- Restart prometheus
delegate_to: "{{ inventory_hostname }}"
synchronize:
ansible.posix.synchronize:
src: "/usr/local/src/prometheus-{{ prometheus_version }}.linux-amd64/console_libraries"
dest: /etc/prometheus
delete: True
Expand All @@ -103,7 +103,7 @@
- not ansible_check_mode
notify:
- Restart prometheus
file:
ansible.builtin.file:
path: /etc/prometheus/console_libraries
owner: prometheus
group: prometheus
Expand All @@ -119,7 +119,7 @@
notify:
- Restart prometheus
delegate_to: "{{ inventory_hostname }}"
synchronize:
ansible.posix.synchronize:
src: "/usr/local/src/prometheus-{{ prometheus_version }}.linux-amd64/consoles"
dest: /etc/prometheus
delete: True
Expand All @@ -134,7 +134,7 @@
- not ansible_check_mode
notify:
- Restart prometheus
file:
ansible.builtin.file:
path: /etc/prometheus/consoles
owner: prometheus
group: prometheus
Expand All @@ -152,7 +152,7 @@
loop:
- prometheus
- promtool
copy:
ansible.builtin.copy:
src: "/usr/local/src/prometheus-{{ prometheus_version }}.linux-amd64/{{ item }}"
dest: "/usr/bin/{{ item }}"
remote_src: True
Expand All @@ -165,7 +165,7 @@
- name: Drop tsdb binary
when:
- prometheus_installation == 'native'
file:
ansible.builtin.file:
path: /usr/bin/tsdb
state: absent
tags:
Expand All @@ -174,7 +174,7 @@
- name: Write general config
notify:
- Restart prometheus
template:
ansible.builtin.template:
src: config.j2
dest: /etc/prometheus/config.yml
owner: "{{ 'prometheus' if prometheus_installation == 'native' else 'nobody' }}"
Expand All @@ -190,7 +190,7 @@
loop_control:
label: "{{ item.name }}"
when: item.url | default(False) and item.state | default("present") == "present"
get_url:
ansible.builtin.get_url:
url: "{{ item.url }}"
dest: "{{ item.path | default('/etc/prometheus/rules') }}/{{ item.name }}.yml"
owner: "{{ 'prometheus' if prometheus_installation == 'native' else 'nobody' }}"
Expand All @@ -206,7 +206,7 @@
loop_control:
label: "{{ item.name }}"
when: item.content | default(False) and item.state | default("present") == "present"
copy:
ansible.builtin.copy:
content: "{{ item.content }}"
dest: "{{ item.path | default('/etc/prometheus/rules') }}/{{ item.name }}.yml"
owner: "{{ 'prometheus' if prometheus_installation == 'native' else 'nobody' }}"
Expand All @@ -222,7 +222,7 @@
loop_control:
label: "{{ item.name }}"
when: item.src | default(False) and item.state | default("present") == "present"
copy:
ansible.builtin.copy:
src: "{{ item.src }}"
dest: "{{ item.path | default('/etc/prometheus/rules') }}/{{ item.name }}.yml"
owner: "{{ 'prometheus' if prometheus_installation == 'native' else 'nobody' }}"
Expand All @@ -238,7 +238,7 @@
loop_control:
label: "{{ item.name }}"
when: item.state | default("present") == "absent"
file:
ansible.builtin.file:
path: "{{ item.path | default('/etc/prometheus/rules') }}/{{ item.name }}.yml"
state: absent
tags:
Expand All @@ -247,7 +247,7 @@
- name: Write default config
notify:
- Restart prometheus
template:
ansible.builtin.template:
src: default.j2
dest: /etc/default/prometheus
owner: root
Expand All @@ -259,7 +259,7 @@
- name: Write service file
notify:
- Restart prometheus
template:
ansible.builtin.template:
src: service.j2
dest: /etc/systemd/system/prometheus.service
owner: root
Expand All @@ -272,7 +272,7 @@
when:
- prometheus_installation == 'docker'
- prometheus_pull_image
docker_image:
community.docker.docker_image:
name: "{{ prometheus_image }}"
source: pull
tags:
Expand All @@ -282,13 +282,13 @@
when:
- prometheus_installation == 'docker'
- prometheus_network | default(False)
docker_network:
community.docker.docker_network:
name: '{{ prometheus_network }}'
tags:
- prometheus

- name: Start prometheus service
systemd:
ansible.builtin.systemd:
name: prometheus
state: started
daemon_reload: True
Expand All @@ -300,15 +300,15 @@
- name: Remove install directory
when:
- prometheus_installation == 'native'
file:
ansible.builtin.file:
path: "/usr/local/src/prometheus-{{ prometheus_version }}.linux-amd64"
state: absent
tags:
- prometheus

- name: Include oauth2 tasks
when: prometheus_oauth2_enabled | default(False)
include_tasks: oauth2.yml
ansible.builtin.include_tasks: oauth2.yml
tags:
- prometheus
- oauth2
Expand Down
Loading

0 comments on commit cff737e

Please sign in to comment.