From 55ec0d4d6b3aff99a8ea53ca2ce65acccb6e7563 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Wed, 25 Nov 2020 15:21:00 +0100 Subject: [PATCH] First bits of a role that installs pgadmin --- README.md | 26 ++---- defaults/main.yml | 32 +++++++- meta/main.yml | 56 +++++-------- tasks/main.yml | 7 +- tasks/pgadmin_deb.yml | 17 ++++ tasks/pgadmin_el.yml | 14 ++++ tasks/pgadmin_wheel.yml | 35 ++++++++ templates/config_local.py.j2 | 115 +++++++++++++++++++++++++++ templates/pgadmin.service.systemd.j2 | 17 ++++ 9 files changed, 265 insertions(+), 54 deletions(-) create mode 100644 tasks/pgadmin_deb.yml create mode 100644 tasks/pgadmin_el.yml create mode 100644 tasks/pgadmin_wheel.yml create mode 100644 templates/config_local.py.j2 create mode 100644 templates/pgadmin.service.systemd.j2 diff --git a/README.md b/README.md index 3637db8..4522dd7 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,21 @@ 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 installs pgAdmin as a service, 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 +pgadmin_as_package: True +``` 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 } +* python3-environment, when installed from the wheel file and not as a distribution package License ------- @@ -35,4 +25,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..82e1d92 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,32 @@ --- -# defaults file for ansible-role-template \ No newline at end of file +pgadmin_as_package: True +pgadmin_deb_repo_key: 'https://www.pgadmin.org/static/packages_pgadmin_org.pub' +pgadmin_deb_repo: 'deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/{{ ansible_distribution_release }} pgadmin4 main' +pgadmin_el_repo: 'https://ftp.postgresql.org/pub/pgadmin/pgadmin4/yum/pgadmin4-redhat-repo-1-1.noarch.rpm' + +pgadmin_pkg_name: 'pgadmin4-web' +pgadmin_setup_script: '/usr/pgadmin4/bin/setup-web.sh' + + +# When not using the package +pgadmin_user: pgadmin +pgadmin_home: /opt/pgadmin + +pgadmin_workdir: /usr/local/lib/python2.7/dist-packages/pgadmin4 + +py3_env_pip_pkgs: + - flask + - flask_babelex + - flask_login + - flask_mail + - flask_paranoid + - flask_security + - flask_sqlalchemy + - simplejson + - python-dateutil + - flask_migrate + - flask_gravatar + - psutil + - sqlparse + - flask_htmlmin + diff --git a/meta/main.yml b/meta/main.yml index 81bda14..cf9bb69 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,46 +1,34 @@ 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: + - pgadmin + - postgresql + +dependencies: + - src: git+https://gitea-s2i2s.isti.cnr.it/ISTI-ansible-roles/ansible-role-python3-environment.git + version: master + name: python3-environment + state: latest + when: not pgadmin_as_package - 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. -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..6848f74 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: pgadmin_deb.yml + when: ansible_distribution_file_variety == "Debian" +- import_tasks: pgadmin_el.yml + when: ansible_distribution_file_variety == "RedHat" +- import_tasks: pgadmin_wheel.yml + when: not pgadmin_as_package diff --git a/tasks/pgadmin_deb.yml b/tasks/pgadmin_deb.yml new file mode 100644 index 0000000..f4997e6 --- /dev/null +++ b/tasks/pgadmin_deb.yml @@ -0,0 +1,17 @@ +--- +- name: Manage the deb repo + block: + - name: Install the pgAdmin deb repo key + apt_key: url={{ pgadmin_deb_repo_key }} state=present + + - name: Install the pgAdmin deb repo + apt_repository: repo='{{ pgadmin_deb_repo }}' state=present update_cache=yes + + tags: pgadmin + +- name: Manage the pgAdmin package + block: + - name: Install the deb pgAdmin package + apt: pkg={{ pgadmin_pkg_name }} state=present cache_valid_time=3600 + + tags: pgadmin diff --git a/tasks/pgadmin_el.yml b/tasks/pgadmin_el.yml new file mode 100644 index 0000000..5648aa6 --- /dev/null +++ b/tasks/pgadmin_el.yml @@ -0,0 +1,14 @@ +--- +- name: Manage the el repo + block: + - name: Install the pgAdmin el repo + yum: pkg='{{ pgadmin_el_repo }}' state=present + + tags: pgadmin + +- name: Manage the pgAdmin package + block: + - name: Install the el pgAdmin package + yum: pkg={{ pgadmin_pkg_name }} state=present + + tags: pgadmin diff --git a/tasks/pgadmin_wheel.yml b/tasks/pgadmin_wheel.yml new file mode 100644 index 0000000..cd35e22 --- /dev/null +++ b/tasks/pgadmin_wheel.yml @@ -0,0 +1,35 @@ +--- +- block: + - name: Create a user that will be the owner of the pgadmin files + user: name={{ pgadmin_user }} home={{ pgadmin_home }} createhome=no shell=/usr/sbin/nologin system=yes + + - name: Download the pgadmin python installer + get_url: url=https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v4.1/pip/pgadmin4-4.1-py2.py3-none-any.whl dest={{ pgadmin_home }} + + - name: Install the pgadmin pip modules + shell: python3 -m wheel install {{ pgadmin_home }}/pgadmin4-4.1-py2.py3-none-any.whl + args: + creates: '/usr/local/lib/python3.6/dist-packages/pgadmin4' + register: pgadmin_install + + - name: Install the pgadmin configuration file + template: src=config_local.py.j2 dest=/usr/local/lib/python3.6/dist-packages/pgadmin4/config_local.py owner=root group=root + + - name: run the pgadmin setup if we just installed the pip modules + shell: cd /usr/local/lib/python3.6/dist-packages/pgadmin4 ; python3 setup.py + when: pgadmin_install is changed + + - name: Install the pgAdmin systemd unit + template: src=pgadmin.service.systemd.j2 dest=/etc/systemd/system/pgadmin.service + register: systemd_reload + + - name: systemd reload + command: systemctl daemon-reload + when: systemd_reload is changed + + - name: Ensure that the pgAdmin service is enabled and running + service: name=pgadmin state=started enabled=yes + + when: not pgadmin_as_package + tags: [ 'pgadmin' ] + diff --git a/templates/config_local.py.j2 b/templates/config_local.py.j2 new file mode 100644 index 0000000..df816d4 --- /dev/null +++ b/templates/config_local.py.j2 @@ -0,0 +1,115 @@ +# -*- coding: utf-8 -*- + +# Application version suffix, e.g. 'beta1', 'dev'. Usually an empty string +# for GA releases. +APP_SUFFIX = '' + +########################################################################## +# Server settings +########################################################################## + +# The server mode determines whether or not we're running on a web server +# requiring user authentication, or desktop mode which uses an automatic +# default login. +# +# DO NOT DISABLE SERVER MODE IF RUNNING ON A WEBSERVER!! +# +# We only set SERVER_MODE if it's not already set. That's to allow the +# runtime to force it to False. +# +# NOTE: If you change the value of SERVER_MODE in an included config file, +# you may also need to redefine any values below that are derived +# from it, notably various paths such as LOG_FILE and anything +# using DATA_DIR. + + +# This option allows the user to host the application on a LAN +# Default hosting is on localhost (DEFAULT_SERVER='localhost'). +# To host pgAdmin4 over LAN set DEFAULT_SERVER='0.0.0.0' (or a specific +# adaptor address. +# +# NOTE: This is NOT recommended for production use, only for debugging +# or testing. Production installations should be run as a WSGI application +# behind Apache HTTPD. +DEFAULT_SERVER = '127.0.0.1' + +# The default port on which the app server will listen if not set in the +# environment by the runtime +DEFAULT_SERVER_PORT = 5050 + +# Hashing algorithm used for password storage +SECURITY_PASSWORD_HASH = 'pbkdf2_sha512' + +# NOTE: CSRF_SESSION_KEY, SECRET_KEY and SECURITY_PASSWORD_SALT are no +# longer part of the main configuration, but are stored in the +# configuration databases 'keys' table and are auto-generated. + +# Should HTML be minified on the fly when not in debug mode? +# NOTE: The HTMLMIN module doesn't work with Python 2.6, so this option +# has no effect on <= Python 2.7. +MINIFY_PAGE = True + +DATA_DIR = '/opt/pgadmin/data' + +########################################################################## +# Log settings +########################################################################## + +# Debug mode? +DEBUG = False + +LOG_FILE = '/opt/pgadmin/logs/pgadmin4.log' + +########################################################################## +# User account and settings storage +########################################################################## + +# The default path to the SQLite database used to store user accounts and +# settings. This default places the file in the same directory as this +# config file, but generates an absolute path for use througout the app. +SQLITE_PATH = '/opt/pgadmin/db/pgadmin.db' + +# Allow database connection passwords to be saved if the user chooses. +# Set to False to disable password saving. +ALLOW_SAVE_PASSWORD = True + +########################################################################## +SESSION_DB_PATH = '/opt/pgadmin/sessions' + +SESSION_COOKIE_NAME = 'pga4_session' + +# Flask-Security overrides Flask-Mail's MAIL_DEFAULT_SENDER setting, so +# that should be set as such: +SECURITY_EMAIL_SENDER = 'no-reply@d4science.org' + +# Check for new versions of the application? +UPGRADE_CHECK_ENABLED = False + + +STORAGE_DIR = '/opt/pgadmin/storage' + +########################################################################## +# Default locations for binary utilities (pg_dump, pg_restore etc) +# +# These are intentionally left empty in the main config file, but are +# expected to be overridden by packagers in config_distro.py. +# +# A default location can be specified for each database driver ID, in +# a dictionary. Either an absolute or relative path can be specified. +# In cases where it may be difficult to know what the working directory +# is, "$DIR" can be specified. This will be replaced with the path to the +# top-level pgAdmin4.py file. For example, on macOS we might use: +# +# $DIR/../../SharedSupport +# +########################################################################## +DEFAULT_BINARY_PATHS = { + "pg": "", + "ppas": "", + "gpdb": "" +} + +########################################################################## +# SSH Tunneling supports only for Python 2.7 and 3.4+ +########################################################################## +SUPPORT_SSH_TUNNEL = False diff --git a/templates/pgadmin.service.systemd.j2 b/templates/pgadmin.service.systemd.j2 new file mode 100644 index 0000000..3f21158 --- /dev/null +++ b/templates/pgadmin.service.systemd.j2 @@ -0,0 +1,17 @@ +[Unit] +Description=pgadmin - Postgresql Admin service +After=network.target + +[Service] +Type=simple +Restart=on-failure +User={{ pgadmin_user }} +Group={{ pgadmin_user }} +WorkingDirectory=/usr/local/lib/python2.7/dist-packages/pgadmin4 + +ExecStart=/usr/bin/python2 pgAdmin4.py + +[Install] +WantedBy=multi-user.target +Alias=pgadmin4.service +