Skip to content

Commit

Permalink
PMM-12530 clean up ansible scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Dec 14, 2023
1 parent 78e40b4 commit e6fc9b5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 74 deletions.
100 changes: 35 additions & 65 deletions build/ansible/pmm/post-build-actions.yml
Original file line number Diff line number Diff line change
@@ -1,67 +1,45 @@
---
# This playbook is used as a post build actions for all pmm images (AMI/OVF/Docker).
# This playbook runs post build tasks for all pmm distributions (AMI/OVF/Docker/Digitalocean).

- hosts: localhost
- hosts: all
become: yes
gather_facts: yes
vars:
pmm_client_repos: "original testing"
pmm_client_repos_final: "original release"
pmm_server_distribution: "docker"

tasks:
# pmm-managed checks that if /srv/pmm-distribution exist, it contains "docker", "ovf", or "ami" (all lowercase)
- name: Detect distribution | Create '/srv/pmm-distribution' file for Docker
when: ansible_virtualization_type == "docker"
# Possible values are: docker, ovf, ami, digitalocean.
# TODO: refactor this and pmm-managed.
# https://jira.percona.com/browse/PMM-4991
- name: Create a distribution file for Docker
copy:
content: "docker"
content: "{{ pmm_server_distribution}}"
dest: /srv/pmm-distribution

- name: Detect distribution | Create '/srv/pmm-distribution' file for OVF
when: ansible_virtualization_type == "virtualbox"
copy:
content: "ovf"
dest: /srv/pmm-distribution

# TODO https://jira.percona.com/browse/PMM-4991
- name: Detect distribution | Create '/srv/pmm-distribution' file for AMI
when: >
( ansible_virtualization_type == "xen"
or ansible_virtualization_type == "kvm" )
and ansible_system_vendor != "DigitalOcean"
copy:
content: "ami"
dest: /srv/pmm-distribution

- name: Detect distribution | Create '/srv/pmm-distribution' file for DigitalOcean
when: ansible_system_vendor == "DigitalOcean"
copy:
content: "digitalocean"
dest: /srv/pmm-distribution

- name: Disable repo | Disable testing repo for pmm-client
- name: Disable testing repo for pmm-client
command: percona-release disable {{ pmm_client_repos }}

- name: Enable repo | Enable release repo for pmm-client
- name: Enable release repo for pmm-client
command: percona-release enable {{ pmm_client_repos_final }}

- name: Install glibc-langpack-en | EL9
dnf:
name: glibc-langpack-en
state: present
update_cache: yes
when:
- ansible_virtualization_type != "docker"
- ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux'
- ansible_distribution_major_version == '9'

- name: Set locale to en_US.utf8 | EL9
command: localectl set-locale LANG=en_US.utf8
when:
- ansible_virtualization_type != "docker"
- ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux'
- ansible_distribution_major_version == '9'

- name: pmm-agent | Setup pmm-agent
# These two tasks are left for reference.
# - name: Install glibc-langpack-en
# dnf:
# name: glibc-langpack-en
# state: present
# update_cache: yes
# when:
# - ansible_virtualization_type != "docker"

# - name: Set locale to en_US.utf8
# command: localectl set-locale LANG=en_US.utf8
# when:
# - ansible_virtualization_type != "docker"

- name: Set up pmm-agent
command: >
pmm-agent setup
--config-file=/usr/local/percona/pmm/config/pmm-agent.yaml
Expand All @@ -70,21 +48,18 @@
--server-address=127.0.0.1:8443
--server-insecure-tls
- name: Reread supervisord configuration EL9
when:
- ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux'
- ansible_distribution_major_version == '9'
command: /usr/local/bin/supervisorctl reread
- name: Reread supervisord configuration
command: supervisorctl reread
become: true
become_user: pmm
become_method: su
register: reread_result
changed_when: "'No config updates to processes' not in reread_result.stdout"

- name: See which service configs changed
debug: var=reread_result.stdout_lines

- name: Stop pmm-managed before deleting the database
when:
- ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux'
- ansible_distribution_major_version == '9'
supervisorctl:
name: pmm-managed
state: stopped
Expand All @@ -93,9 +68,6 @@
become_method: su

- name: Remove pmm-managed database
when:
- ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux'
- ansible_distribution_major_version == '9'
postgresql_db:
login_user: postgres
name: pmm-managed
Expand All @@ -107,16 +79,14 @@
name: pmm-managed
state: absent

- name: Stop supervisord service for AMI/OVF
when: ansible_virtualization_type != "docker"
service: name=supervisord state=stopped enabled=yes

- name: Stop supervisord service for docker
when: ansible_virtualization_type == "docker"
shell: supervisorctl shutdown
command: supervisorctl shutdown
become: true
become_user: pmm
become_method: su

- name: Cleanup dnf cache
shell: dnf clean all
command: dnf clean all

# "yum clean all" function will only remove cache from configured yum repositories
# Details: https://bugzilla.redhat.com/show_bug.cgi?id=1357083
Expand Down
15 changes: 8 additions & 7 deletions build/ansible/roles/pmm-images/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
gpgkey: file:///etc/pki/rpm-gpg/PERCONA-PACKAGING-KEY

# local yum repo for building pmm server docker image in autobuild jobs
- name: Packages | Add a local YUM repository
- name: Add a local YUM repository
when: ansible_virtualization_type == "docker"
yum_repository:
name: local
Expand All @@ -30,13 +30,13 @@
# To workaround the package's incompatibility with RHEL9, we have to ignore errors :(
# Error: `Failed to validate GPG signature for percona-release-1.0-27.noarch`
# Despite the error, this will still install the repo and the GPG key
- name: Packages | Install percona-release rpm
- name: Add percona-release repository
yum:
name: https://repo.percona.com/yum/percona-release-latest.noarch.rpm
state: installed
ignore_errors: True

- name: Packages | Update OS EL9
- name: Update OS packages
when:
- ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux'
- ansible_distribution_major_version == '9'
Expand All @@ -45,7 +45,7 @@
state: latest
disablerepo: percona-release-x86_64

- name: Packages | Install OS tools for EL9
- name: Install OS tools
when:
- ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux'
- ansible_distribution_major_version == '9'
Expand All @@ -55,7 +55,7 @@
- python3.11-pip
- python3.11-psycopg2
- rsync
- libsqlite3x-devel # package does not come pre-installed on EL9
# - libsqlite3x-devel # package does not come pre-installed on EL9

- name: Install ansible-core and ansible collections
when:
Expand All @@ -80,7 +80,8 @@
- { name: nginx, gid: 1001 }
- { name: clickhouse, gid: 1002 }

- name: Create users | Create users
# Note: nginx and clickhouse users will get removed in post-build.
- name: Create users
user:
name: "{{ item.name }}"
uid: "{{ item.uid }}"
Expand Down Expand Up @@ -172,7 +173,7 @@
include_role:
name: pmm-client

- name: Create tmp dirs | Create tmp dirs
- name: Create tmp dirs
when: ansible_virtualization_type != "docker"
command: /usr/bin/systemd-tmpfiles --create --remove --boot --exclude-prefix=/dev

Expand Down
4 changes: 2 additions & 2 deletions update/ansible/playbook/tasks/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
command: supervisorctl reread
become: true
become_user: pmm
become_method: su
become_method: su
register: reread_result
changed_when: "'No config updates to processes' not in reread_result.stdout"

Expand Down Expand Up @@ -110,7 +110,7 @@
become: true
become_user: pmm
become_method: su
changed_when: true
# changed_when: true
with_nested:
- - nginx
- grafana
Expand Down

0 comments on commit e6fc9b5

Please sign in to comment.