From 71bec92ff583f288e13c79bed881e0033ebbb337 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Tue, 23 Mar 2021 15:35:03 +0100 Subject: [PATCH] First commit. --- README.md | 27 ++++-------- defaults/main.yml | 23 ++++++++++- meta/main.yml | 55 ++++++++++--------------- tasks/main.yml | 7 +++- tasks/timescale_db_deb.yml | 35 ++++++++++++++++ tasks/timescale_db_el.yml | 32 ++++++++++++++ templates/timescale_timescaledb.repo.j2 | 10 +++++ vars/main.yml | 4 +- 8 files changed, 138 insertions(+), 55 deletions(-) create mode 100644 tasks/timescale_db_deb.yml create mode 100644 tasks/timescale_db_el.yml create mode 100644 templates/timescale_timescaledb.repo.j2 diff --git a/README.md b/README.md index 3637db8..4bd2746 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,22 @@ Role Name ========= -A brief description of the role goes here. - -Requirements ------------- - -Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. +A role that Role Variables -------------- -A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. +The most important variables are listed below: + +``` yaml +users_system_users: + - { login: 'foo', name: "Foo Bar", home: '{{ users_home_dir }}', createhome: 'yes', ssh_key: '{{ foo_ssh_key }}', shell: '/bin/bash', admin: False, log_as_root: False } +``` Dependencies ------------ -A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. - -Example Playbook ----------------- - -Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: - - - hosts: servers - roles: - - { role: username.rolename, x: 42 } +None License ------- @@ -35,4 +26,4 @@ EUPL-1.2 Author Information ------------------ -An optional section for the role authors to include contact information, or a website (HTML is not allowed). +Andrea Dell'Amico, diff --git a/defaults/main.yml b/defaults/main.yml index 95d3c70..2aa06b5 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,23 @@ --- -# defaults file for ansible-role-template \ No newline at end of file +timescale_db_ubuntu_repo: 'ppa:timescale/timescaledb-ppa' + +timescale_db_pkg: 'timescaledb-2-postgresql-{{ psql_version }}' +timescale_db_deb_pkgs: '{{ timescale_db_pkg }}' + +timescale_db_el_pkgs: + - '{{ timescale_db_pkg }}' + - libpq5-devel + +timescaledb_configuration_settings: + - { name: 'timescaledb.last_tuned', value: "'{{ ansible_date_time.date }}T{{ ansible_date_time.time }}{{ ansible_date_time.tz_offset }}'", set: 'True' } + - { name: 'timescaledb.last_tuned_version', value: "'0.11.0'", set: 'True' } + - { name: 'timescaledb.max_background_workers', value: '{{ ansible_processor_vcpus * 2 }}', set: 'True' } + - { name: 'max_worker_processes', value: '{{ (ansible_processor_vcpus * 4) - 1 }}', set: 'True' } + - { name: 'max_parallel_workers_per_gather', value: '{{ (ansible_processor_vcpus / 2) | int }}', set: 'True' } + - { name: 'max_parallel_workers ', value: '{{ ansible_processor_vcpus }}', set: 'True' } + - { name: 'default_statistics_target', value: '{{ (ansible_memtotal_mb / 16) | int }}', set: 'True' } + - { name: 'random_page_cost', value: '1.1', set: 'True' } + - { name: 'checkpoint_completion_target', value: '0.9', set: 'True' } + - { name: 'max_locks_per_transaction', value: '{{ ((ansible_memtotal_mb / 512) * ansible_processor_vcpus) | int }}', set: 'True' } + - { name: 'effective_io_concurrency', value: '200', set: 'True' } + diff --git a/meta/main.yml b/meta/main.yml index 81bda14..27caa86 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,46 +1,33 @@ galaxy_info: - author: your name - description: your description - company: your company (optional) + author: Andrea Dell'Amico + description: Systems Architect + company: ISTI-CNR - # If the issue tracker for your role is not on github, uncomment the - # next line and provide a value - issue_tracker_url: https://support.d4science.org/projects/automatic-provisioning/issues + issue_tracker_url: https://redmine-s2i2s.isti.cnr.it/projects/provisioning - license: EUPL-1.2 + license: EUPL 1.2+ min_ansible_version: 2.8 - # If this a Container Enabled role, provide the minimum Ansible Container version. - # min_ansible_container_version: - - # Optionally specify the branch Galaxy will use when accessing the GitHub - # repo for this role. During role install, if no tags are available, - # Galaxy will use this branch. During import Galaxy will access files on - # this branch. If Travis integration is configured, only notifications for this - # branch will be accepted. Otherwise, in all cases, the repo's default branch - # (usually master) will be used. - #github_branch: - - # - # Provide a list of supported platforms, and for each platform a list of versions. - # If you don't wish to enumerate all versions for a particular platform, use 'all'. # To view available platforms and versions (or releases), visit: # https://galaxy.ansible.com/api/v1/platforms/ # platforms: - - name: Ubuntu - versions: - - bionic + - name: Ubuntu + versions: + - bionic + - name: EL + versions: + - 7 - galaxy_tags: [] - # List tags for your role here, one per line. A tag is a keyword that describes - # and categorizes the role. Users find roles by searching for tags. Be sure to - # remove the '[]' above, if you add tags to this list. - # - # NOTE: A tag is limited to a single word comprised of alphanumeric characters. - # Maximum 20 tags per role. + galaxy_tags: + - DB + - timeseries + - timescaledb + +dependencies: + - src: git+https://gitea-s2i2s.isti.cnr.it/ISTI-ansible-roles/ansible-role-postgresql.git + version: master + name: postgresql + state: latest -dependencies: [] - # List your role dependencies here, one per line. Be sure to remove the '[]' above, - # if you add dependencies to this list. \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index 53c6cae..81cb870 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,7 @@ --- -# tasks file for ansible-role-template \ No newline at end of file +- import_tasks: timescale_db_deb.yml + when: ansible_distribution_file_variety == "Debian" + +- import_tasks: timescale_db_el.yml + when: ansible_distribution_file_variety == "RedHat" + diff --git a/tasks/timescale_db_deb.yml b/tasks/timescale_db_deb.yml new file mode 100644 index 0000000..dfaa6b2 --- /dev/null +++ b/tasks/timescale_db_deb.yml @@ -0,0 +1,35 @@ +--- +- name: Manage the installation on deb based distributions + block: + - name: Install the Ubuntu PPA + apt_repository: + repo: '{{ timescale_db_ubuntu_repo }}' + update_cache: True + state: present + when: ansible_distribution == "Ubuntu" + + - name: Install the timescale DB package on deb + apt: + pkg: '{{ timescale_db_deb_pkgs }}' + state: present + cache_valid_time: 1800 + + tags: [ postgresql, timescale, timescaledb ] + +- name: Manage the timescale + postgresql settings + block: + - name: Enable the TimeScaleDB extension + become: True + become_user: postgres + action: configfile path={{ psql_conf_dir }}/postgresql.conf key=shared_preload_libraries value="'timescaledb'" + notify: Restart postgresql + + - name: TimeScaleDB setting for postgresql + become: True + become_user: postgres + action: configfile path={{ psql_conf_dir }}/postgresql.conf key={{ item.name }} value="{{ item.value }}" + with_items: '{{ timescaledb_configuration_settings }}' + when: item.set == 'True' + notify: Reload postgresql + + tags: [ 'postgresql', 'postgres', 'pg_conf', 'timescale', 'timescaledb', 'timescale_conf' ] diff --git a/tasks/timescale_db_el.yml b/tasks/timescale_db_el.yml new file mode 100644 index 0000000..d05edf1 --- /dev/null +++ b/tasks/timescale_db_el.yml @@ -0,0 +1,32 @@ +--- +- name: Manage the installation on EL based distributions + block: + - name: Install the repository configuration on EL + template: + src: timescale_timescaledb.repo.j2 + dest: /etc/yum.repos.d/timescale_timescaledb.repo + + - name: Install the timescale DB package on EL + yum: + pkg: '{{ timescale_db_el_pkgs }}' + state: present + + tags: [ postgresql, timescale, timescaledb ] + +- name: Manage the timescale + postgresql settings on EL based distributions + block: + - name: Enable the TimeScaleDB extension on EL + become: True + become_user: postgres + action: configfile path={{ psql_el_conf_dir }}/postgresql.conf key=shared_preload_libraries value="'timescaledb'" + notify: Restart postgresql + + - name: TimeScaleDB setting for postgresql on EL + become: True + become_user: postgres + action: configfile path={{ psql_el_conf_dir }}/postgresql.conf key={{ item.name }} value="{{ item.value }}" + with_items: '{{ timescaledb_configuration_settings }}' + when: item.set == 'True' + notify: Reload postgresql + + tags: [ 'postgresql', 'postgres', 'pg_conf', 'timescale', 'timescaledb', 'timescale_conf' ] diff --git a/templates/timescale_timescaledb.repo.j2 b/templates/timescale_timescaledb.repo.j2 new file mode 100644 index 0000000..f200b67 --- /dev/null +++ b/templates/timescale_timescaledb.repo.j2 @@ -0,0 +1,10 @@ +[timescale_timescaledb] +name=timescale_timescaledb +baseurl=https://packagecloud.io/timescale/timescaledb/el/{{ ansible_distribution_major_version }}/\$basearch +repo_gpgcheck=1 +gpgcheck=0 +enabled=1 +gpgkey=https://packagecloud.io/timescale/timescaledb/gpgkey +sslverify=1 +sslcacert=/etc/pki/tls/certs/ca-bundle.crt +metadata_expire=300 diff --git a/vars/main.yml b/vars/main.yml index 3808477..46d9c75 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,4 @@ --- -# vars file for ansible-role-template \ No newline at end of file +psql_version: 13 +pg_use_postgresql_org_repo: True +psql_postgresql_install: True