You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by jh...@apache.org on 2021/01/29 20:35:21 UTC
[trafficcontrol] branch master updated: Postgres version agnostic
(#5420)
This is an automated email from the ASF dual-hosted git repository.
jhg03a pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 5397a4f Postgres version agnostic (#5420)
5397a4f is described below
commit 5397a4fb17a24c255d698ce9594f37562b531c89
Author: Ashish P <as...@gmail.com>
AuthorDate: Fri Jan 29 13:35:08 2021 -0700
Postgres version agnostic (#5420)
* updating Ansible roles so that postgresql installation is version agnostic
* forcing string to use .split to parse major/minor versions
* adding license headers
* Adding changelog
* Adding validation to postgres version being passed for traffic_opsdb & traffic_ops roles
* Syntax fix for assert tasks on validation
* traffic_ops task update in removing 9.6 hardcode
Co-authored-by: apaudy028 <as...@cable.comcast.com>
---
CHANGELOG.md | 1 +
.../ansible/roles/traffic_ops/defaults/main.yml | 2 +-
.../roles/traffic_ops/tasks/traffic_ops.yml | 11 ++++--
.../ansible/roles/traffic_ops/vars/main.yml | 30 +++++++++++++++++
.../ansible/roles/traffic_opsdb/defaults/main.yml | 8 ++---
.../roles/traffic_opsdb/tasks/traffic_opsdb.yml | 22 ++++++++----
.../ansible/roles/traffic_opsdb/vars/main.yml | 39 ++++++++++++++++++++++
7 files changed, 99 insertions(+), 14 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d173696..bcf2f19 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -39,6 +39,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- [#5407](https://github.com/apache/trafficcontrol/issues/5407) - Make sure that you cannot add two servers with identical content
- [#2881](https://github.com/apache/trafficcontrol/issues/2881) - Some API endpoints have incorrect Content-Types
- [#5311](https://github.com/apache/trafficcontrol/issues/5311) - Better TO log messages when failures calling TM CacheStats
+- [#5363](https://github.com/apache/trafficcontrol/issues/5363) - Postgresql version changeable by env variable
- [#5364](https://github.com/apache/trafficcontrol/issues/5364) - Cascade server deletes to delete corresponding IP addresses and interfaces
- [#5390](https://github.com/apache/trafficcontrol/issues/5390) - Improve the way TO deals with delivery service server assignments
- [#5339](https://github.com/apache/trafficcontrol/issues/5339) - Ensure Changelog entries for SSL key changes
diff --git a/infrastructure/ansible/roles/traffic_ops/defaults/main.yml b/infrastructure/ansible/roles/traffic_ops/defaults/main.yml
index 266af1f..2e8be7c 100644
--- a/infrastructure/ansible/roles/traffic_ops/defaults/main.yml
+++ b/infrastructure/ansible/roles/traffic_ops/defaults/main.yml
@@ -18,7 +18,7 @@ to_pkg_name: "{% if to_version is defined and to_version != omit %}{{ 'traffic_o
# Postgres Superuser account to use with TO database and user creation
postgresql_admin_user:
postgresql_admin_user_password:
-postgresql_client_pkg_name: "{% if postgresql_version is defined and postgresql_version != omit %}{{ 'postgresql96-'+postgresql_version }}{% else %}postgresql96{% endif %}"
+postgresql_client_pkg_name: "{% if pg_major_version | int < 10 %}postgresql{{pg_major_version}}{{pg_minor_version}}-{{pg_major_version}}.{{pg_minor_version}}.{{pg_build_num}}{% else %}postgresql{{pg_major_version}}-{{pg_major_version}}.{{pg_minor_version}}{% endif %}"
# Local OS Account to use with TrafficOps processes
to_user: trafops # currently hardcoded into TO
diff --git a/infrastructure/ansible/roles/traffic_ops/tasks/traffic_ops.yml b/infrastructure/ansible/roles/traffic_ops/tasks/traffic_ops.yml
index e6cc0d1..0351ef7 100644
--- a/infrastructure/ansible/roles/traffic_ops/tasks/traffic_ops.yml
+++ b/infrastructure/ansible/roles/traffic_ops/tasks/traffic_ops.yml
@@ -12,6 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+- name: Check that valid postgresql version was passed
+ assert:
+ that:
+ - " valid_major_version == 'true' "
+ - " valid_minor_version == 'true' "
+ - " valid_build_version == 'true' "
+
- name: Install Postgres client tools
yum:
name:
@@ -24,8 +31,8 @@
- name: Add Postgres96 bin dir to system-wide $PATH.
copy:
- dest: /etc/profile.d/postgres96-bin.sh
- content: PATH=$PATH:/usr/pgsql-9.6/bin
+ dest: "{{ pg_profile_path }}"
+ content: PATH=$PATH:{{ pg_bin_path }}
- name: Install Traffic Ops
yum:
diff --git a/infrastructure/ansible/roles/traffic_ops/vars/main.yml b/infrastructure/ansible/roles/traffic_ops/vars/main.yml
new file mode 100644
index 0000000..a3016c5
--- /dev/null
+++ b/infrastructure/ansible/roles/traffic_ops/vars/main.yml
@@ -0,0 +1,30 @@
+---
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#determine postgres major and minor versions
+pg_major_version: "{% if postgresql_version is defined and postgresql_version != omit %}{{ (postgresql_version | string).split('.')[0]}}{% else %}9{% endif %}"
+valid_major_version: "{% if pg_major_version | int == 0 %}false{% else %}true{% endif %}"
+
+pg_minor_version: "{% if postgresql_version is defined and postgresql_version != omit %}{{ (postgresql_version | string).split('.')[1]}}{% else %}6{% endif %}"
+valid_minor_version: "{% if pg_minor_version | int == 0 %}false{% else %}true{% endif %}"
+
+pg_build_num: "{% if postgresql_version is defined and pg_major_version | int < 10 and postgresql_version != omit %}{{ (postgresql_version | string).split('.')[2]}}{% else %}11{% endif %}"
+valid_build_version: "{% if pg_major_version | int < 10 and pg_build_num | int == 0 %}false{% else %}true{% endif %}"
+
+#postgres bin PATH
+pg_bin_path: "{% if pg_major_version | int < 10 %}/usr/pgsql-{{pg_major_version}}.{{pg_minor_version}}/bin{%else%}/usr/pgsql-{{pg_major_version}}/bin{%endif%}"
+
+#postgres profile.d path
+pg_profile_path: "{% if pg_major_version | int < 10 %}/etc/profile.d/postgres{{pg_major_version}}{{pg_minor_version}}-bin.sh{%else%}/etc/profile.d/postgres{{pg_major_version}}-bin.sh{%endif%}"
diff --git a/infrastructure/ansible/roles/traffic_opsdb/defaults/main.yml b/infrastructure/ansible/roles/traffic_opsdb/defaults/main.yml
index 7e9b7b8..b15b14a 100644
--- a/infrastructure/ansible/roles/traffic_opsdb/defaults/main.yml
+++ b/infrastructure/ansible/roles/traffic_opsdb/defaults/main.yml
@@ -15,9 +15,9 @@
install_traffic_opsdb: false
initialize_traffic_opsdb: false
-postgresql_server_pkg_name: "{% if postgresql_version is defined and postgresql_version != omit %}{{ 'postgresql96-server-'+postgresql_version }}{% else %}postgresql96-server{% endif %}"
-postgresql_client_pkg_name: "{% if postgresql_version is defined and postgresql_version != omit %}{{ 'postgresql96-'+postgresql_version }}{% else %}postgresql96{% endif %}"
-postgresql_devel_pkg_name: "{% if postgresql_version is defined and postgresql_version != omit %}{{ 'postgresql96-devel-'+postgresql_version }}{% else %}postgresql96-devel{% endif %}"
+postgresql_server_pkg_name: "{% if pg_major_version | int < 10 %}postgresql{{pg_major_version}}{{pg_minor_version}}-server-{{pg_major_version}}.{{pg_minor_version}}.{{pg_build_num}}{% elif pg_major_version | int >= 10 %}postgresql{{pg_major_version}}-server-{{pg_major_version}}.{{pg_minor_version}}{% endif %}"
+postgresql_client_pkg_name: "{% if pg_major_version | int < 10 %}postgresql{{pg_major_version}}{{pg_minor_version}}-{{pg_major_version}}.{{pg_minor_version}}.{{pg_build_num}}{% else %}postgresql{{pg_major_version}}-{{pg_major_version}}.{{pg_minor_version}}{% endif %}"
+postgresql_devel_pkg_name: "{% if pg_major_version | int < 10 %}postgresql{{pg_major_version}}{{pg_minor_version}}-devel-{{pg_major_version}}.{{pg_minor_version}}.{{pg_build_num}}{% else %}postgresql{{pg_major_version}}-devel-{{pg_major_version}}.{{pg_minor_version}}{% endif %}"
# Local OS User to use for Postgres Processes
postgresql_user: postgres
@@ -27,7 +27,7 @@ postgresql_group: postgres
postgresql_port: 5432
# Postgres PGDATA directory
-postgresql_datadir: /var/lib/pgsql/9.6/data
+postgresql_datadir: "{% if pg_major_version | int < 10 %}/var/lib/pgsql/{{pg_major_version}}.{{pg_minor_version}}/data{%else%}/var/lib/pgsql/{{pg_major_version}}/data{%endif%}"
# SSL CA root cert to use with SSL Connections
postgresql_certs_ca: "{{ postgresql_datadir }}/lab.rootca.crt"
diff --git a/infrastructure/ansible/roles/traffic_opsdb/tasks/traffic_opsdb.yml b/infrastructure/ansible/roles/traffic_opsdb/tasks/traffic_opsdb.yml
index 84c0af0..9c7fec3 100644
--- a/infrastructure/ansible/roles/traffic_opsdb/tasks/traffic_opsdb.yml
+++ b/infrastructure/ansible/roles/traffic_opsdb/tasks/traffic_opsdb.yml
@@ -11,6 +11,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+- name: Check that valid postgresql version was passed
+ assert:
+ that:
+ - " valid_major_version == 'true' "
+ - " valid_minor_version == 'true' "
+ - " valid_build_version == 'true' "
+
- name: Install Postgres
yum:
name:
@@ -34,7 +41,7 @@
mode: 0755
- name: Initialize database
- shell: "/usr/pgsql-9.6/bin/initdb -D '{{ postgresql_datadir }}'"
+ shell: "{{ pgdb_init_command }}"
become: yes
become_user: "{{ postgresql_user }}"
args:
@@ -43,7 +50,7 @@
- name: Update the systemd definition of PGDATA
ini_file:
create: no
- path: /usr/lib/systemd/system/postgresql-9.6.service
+ path: "{{ pg_service_path }}"
section: Service
option: Environment
value: "PGDATA={{ postgresql_datadir }}"
@@ -52,16 +59,16 @@
systemd:
daemon_reload: yes
-- name: Add Postgres96 bin dir to system-wide $PATH.
+- name: Add Postgres bin dir to system-wide $PATH.
copy:
- dest: /etc/profile.d/postgres96-bin.sh
- content: PATH=$PATH:/usr/pgsql-9.6/bin
+ dest: "{{ pg_profile_path }}"
+ content: PATH=$PATH:{{ pg_bin_path }}
- name: Install psycopg2 python module
easy_install:
name: psycopg2
environment:
- PATH: "/usr/pgsql-9.6/bin:{{ lookup('env', 'PATH') }}"
+ PATH: "{{ pg_bin_path }}:{{ lookup('env', 'PATH') }}"
- name: Render pgpass file for TrafficOps
template:
@@ -123,9 +130,10 @@
enabled: yes
state: started
with_items:
- - postgresql-9.6
+ - "{{ pg_service_name }}"
- name: Wait for TODB to Init Postgres and become available
wait_for:
port: "{{ postgresql_port }}"
delay: 3
+
\ No newline at end of file
diff --git a/infrastructure/ansible/roles/traffic_opsdb/vars/main.yml b/infrastructure/ansible/roles/traffic_opsdb/vars/main.yml
new file mode 100644
index 0000000..3864329
--- /dev/null
+++ b/infrastructure/ansible/roles/traffic_opsdb/vars/main.yml
@@ -0,0 +1,39 @@
+---
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#determine postgres major and minor versions
+pg_major_version: "{% if postgresql_version is defined and postgresql_version != omit %}{{ (postgresql_version | string).split('.')[0]}}{% else %}9{% endif %}"
+valid_major_version: "{% if pg_major_version | int == 0 %}false{% else %}true{% endif %}"
+
+pg_minor_version: "{% if postgresql_version is defined and postgresql_version != omit %}{{ (postgresql_version | string).split('.')[1]}}{% else %}6{% endif %}"
+valid_minor_version: "{% if pg_minor_version | int == 0 %}false{% else %}true{% endif %}"
+
+pg_build_num: "{% if postgresql_version is defined and pg_major_version | int < 10 and postgresql_version != omit %}{{ (postgresql_version | string).split('.')[2]}}{% else %}11{% endif %}"
+valid_build_version: "{% if pg_major_version | int < 10 and pg_build_num | int == 0 %}false{% else %}true{% endif %}"
+
+#postgres bin PATH
+pg_bin_path: "{% if pg_major_version | int < 10 %}/usr/pgsql-{{pg_major_version}}.{{pg_minor_version}}/bin{%else%}/usr/pgsql-{{pg_major_version}}/bin{%endif%}"
+
+#postgres initdb shell command based on version
+pgdb_init_command: "{% if pg_major_version | int < 10 %}/usr/pgsql-{{pg_major_version}}.{{pg_minor_version}}/bin/initdb -D '{{ postgresql_datadir }}'{%else%}/usr/pgsql-{{pg_major_version}}/bin/initdb -D '{{ postgresql_datadir }}'{%endif%}"
+
+#postgres systemd service path
+pg_service_path: "{% if pg_major_version | int < 10 %}/usr/lib/systemd/system/postgresql-{{pg_major_version}}.{{pg_minor_version}}.service{%else%}/usr/lib/systemd/system/postgresql-{{pg_major_version}}.service{%endif%}"
+
+#postgres profile.d path
+pg_profile_path: "{% if pg_major_version | int < 10 %}/etc/profile.d/postgres{{pg_major_version}}{{pg_minor_version}}-bin.sh{%else%}/etc/profile.d/postgres{{pg_major_version}}-bin.sh{%endif%}"
+
+#postgres service name based
+pg_service_name: "{% if pg_major_version | int < 10 %}postgresql-{{pg_major_version}}.{{pg_minor_version}}{%else%}postgresql-{{pg_major_version}}{%endif%}"