From cff737e13193a7ce4f79bc624a34016c9be3307d Mon Sep 17 00:00:00 2001 From: Thomas Boerger Date: Tue, 6 Feb 2024 09:19:31 +0100 Subject: [PATCH] major: used full qualified collection names --- .github/workflows/general.yml | 2 +- handlers/main.yml | 4 +-- meta/requirements.yml | 9 ++++++ molecule/default/prepare.yml | 41 +++++++++++++++++++++++---- molecule/requirements.yml | 6 +++- tasks/main.yml | 52 +++++++++++++++++------------------ tasks/oauth2.yml | 24 ++++++++-------- 7 files changed, 91 insertions(+), 47 deletions(-) create mode 100644 meta/requirements.yml diff --git a/.github/workflows/general.yml b/.github/workflows/general.yml index 15a2fbc..1860b14 100644 --- a/.github/workflows/general.yml +++ b/.github/workflows/general.yml @@ -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 diff --git a/handlers/main.yml b/handlers/main.yml index d96f1dd..0cb7363 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -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 diff --git a/meta/requirements.yml b/meta/requirements.yml new file mode 100644 index 0000000..3cb4f92 --- /dev/null +++ b/meta/requirements.yml @@ -0,0 +1,9 @@ +--- +collections: + - ansible.posix + - community.general + - community.docker + +roles: [] + +... diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index ba10752..2b6e8c7 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -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 + ... diff --git a/molecule/requirements.yml b/molecule/requirements.yml index 586fd81..3cb4f92 100644 --- a/molecule/requirements.yml +++ b/molecule/requirements.yml @@ -1,5 +1,9 @@ --- -collections: [] +collections: + - ansible.posix + - community.general + - community.docker + roles: [] ... diff --git a/tasks/main.yml b/tasks/main.yml index 6c49e72..82f8918 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -4,7 +4,7 @@ - prometheus_installation == 'native' loop: - rsync - package: + ansible.builtin.package: name: "{{ item }}" state: present tags: @@ -13,7 +13,7 @@ - name: Create system group when: - prometheus_installation == 'native' - group: + ansible.builtin.group: name: prometheus system: True state: present @@ -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 @@ -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' }}" @@ -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 @@ -71,7 +71,7 @@ - prometheus_version_changed notify: - Restart prometheus - unarchive: + ansible.builtin.unarchive: src: "{{ prometheus_download }}" dest: /usr/local/src remote_src: True @@ -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 @@ -103,7 +103,7 @@ - not ansible_check_mode notify: - Restart prometheus - file: + ansible.builtin.file: path: /etc/prometheus/console_libraries owner: prometheus group: prometheus @@ -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 @@ -134,7 +134,7 @@ - not ansible_check_mode notify: - Restart prometheus - file: + ansible.builtin.file: path: /etc/prometheus/consoles owner: prometheus group: prometheus @@ -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 @@ -165,7 +165,7 @@ - name: Drop tsdb binary when: - prometheus_installation == 'native' - file: + ansible.builtin.file: path: /usr/bin/tsdb state: absent tags: @@ -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' }}" @@ -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' }}" @@ -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' }}" @@ -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' }}" @@ -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: @@ -247,7 +247,7 @@ - name: Write default config notify: - Restart prometheus - template: + ansible.builtin.template: src: default.j2 dest: /etc/default/prometheus owner: root @@ -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 @@ -272,7 +272,7 @@ when: - prometheus_installation == 'docker' - prometheus_pull_image - docker_image: + community.docker.docker_image: name: "{{ prometheus_image }}" source: pull tags: @@ -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 @@ -300,7 +300,7 @@ - name: Remove install directory when: - prometheus_installation == 'native' - file: + ansible.builtin.file: path: "/usr/local/src/prometheus-{{ prometheus_version }}.linux-amd64" state: absent tags: @@ -308,7 +308,7 @@ - name: Include oauth2 tasks when: prometheus_oauth2_enabled | default(False) - include_tasks: oauth2.yml + ansible.builtin.include_tasks: oauth2.yml tags: - prometheus - oauth2 diff --git a/tasks/oauth2.yml b/tasks/oauth2.yml index 0fdfe09..045d071 100644 --- a/tasks/oauth2.yml +++ b/tasks/oauth2.yml @@ -4,7 +4,7 @@ loop: - python3-passlib - python3-bcrypt - package: + ansible.builtin.package: name: "{{ item }}" state: present tags: @@ -18,7 +18,7 @@ failed_when: False changed_when: False check_mode: False - shell: /usr/bin/prometheus-oauth2 --version 2>&1 + ansible.builtin.shell: /usr/bin/prometheus-oauth2 --version 2>&1 tags: - prometheus - oauth2 @@ -26,7 +26,7 @@ - name: Fact version change when: - prometheus_installation == 'native' - set_fact: + ansible.builtin.set_fact: prometheus_oauth2_version_changed: "{{ prometheus_oauth2_version_check.rc != 0 or (prometheus_oauth2_version_check.stdout_lines is defined and prometheus_oauth2_version not in prometheus_oauth2_version_check.stdout_lines[0]) | bool }}" tags: - prometheus @@ -36,7 +36,7 @@ when: - prometheus_installation == 'native' - prometheus_oauth2_version_changed - unarchive: + ansible.builtin.unarchive: src: "{{ prometheus_oauth2_download }}" dest: /usr/local/src remote_src: True @@ -53,7 +53,7 @@ - not ansible_check_mode notify: - Restart prometheus-oauth2 - copy: + ansible.builtin.copy: src: "/usr/local/src/oauth2-proxy-v{{ prometheus_oauth2_version }}.linux-amd64/oauth2-proxy" dest: /usr/bin/prometheus-oauth2 remote_src: True @@ -71,7 +71,7 @@ label: "{{ item.username }}" notify: - Restart prometheus-oauth2 - htpasswd: + community.general.htpasswd: path: /etc/prometheus/htpasswd name: "{{ item.username }}" password: "{{ item.password }}" @@ -87,7 +87,7 @@ - name: Write default config notify: - Restart prometheus-oauth2 - template: + ansible.builtin.template: src: oauth2/default.j2 dest: /etc/default/prometheus-oauth2 owner: root @@ -100,7 +100,7 @@ - name: Write service file notify: - Restart prometheus-oauth2 - template: + ansible.builtin.template: src: oauth2/service.j2 dest: /etc/systemd/system/prometheus-oauth2.service owner: root @@ -112,7 +112,7 @@ - name: Pull docker image when: prometheus_oauth2_pull_image - docker_image: + community.docker.docker_image: name: "{{ prometheus_oauth2_image }}" source: pull tags: @@ -122,14 +122,14 @@ - name: Create docker network when: - prometheus_oauth2_network | default(False) - docker_network: + community.docker.docker_network: name: '{{ prometheus_oauth2_network }}' tags: - prometheus - oauth2 - name: Start prometheus-oauth2 service - systemd: + ansible.builtin.systemd: name: prometheus-oauth2 state: started daemon_reload: True @@ -142,7 +142,7 @@ - name: Remove install directory when: - prometheus_installation == 'native' - file: + ansible.builtin.file: path: "/usr/local/src/oauth2-proxy-v{{ prometheus_oauth2_version }}.linux-amd64" state: absent tags: