You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
3.5 KiB
117 lines
3.5 KiB
11 months ago
|
---
|
||
|
- name: Check if required variables are defined
|
||
|
ansible.builtin.fail:
|
||
|
msg: "{{ item }} is not defined or empty"
|
||
|
when: |
|
||
|
(vars[item] is undefined)
|
||
|
or (vars[item] is none)
|
||
|
or (vars[item] | trim | length == 0)
|
||
|
with_items:
|
||
|
- koji_domain_name
|
||
|
- koji_db_name
|
||
|
- koji_db_user
|
||
|
- koji_db_password
|
||
|
- koji_db_server_ip
|
||
|
- koji_kerberos_realm
|
||
|
- koji_admin_user
|
||
|
- koji_admin_principal
|
||
|
- koji_admin_password
|
||
|
- koji_hub_principal
|
||
|
- koji_hub_keytab
|
||
|
- koji_web_principal
|
||
|
- koji_web_keytab
|
||
|
- koji_kojira_principal
|
||
|
- koji_kojira_keytab
|
||
|
- koji_web_secret
|
||
|
|
||
|
- name: Install koji package and dependencies
|
||
|
ansible.builtin.dnf:
|
||
|
name:
|
||
|
- koji
|
||
|
- python3-psycopg2
|
||
|
state: installed
|
||
|
|
||
|
- name: Check if Koji database is initialized
|
||
|
community.postgresql.postgresql_query:
|
||
|
db: "{{ koji_db_name }}"
|
||
|
login_user: "{{ koji_db_user }}"
|
||
|
login_password: "{{ koji_db_password }}"
|
||
|
login_host: "{{ koji_db_server_ip }}"
|
||
|
query: SELECT COUNT(*) FROM users
|
||
|
ignore_errors: true
|
||
|
register: koji_database_initialized
|
||
|
changed_when: "koji_database_initialized.failed"
|
||
|
|
||
|
- name: Initialize Koji database
|
||
|
community.postgresql.postgresql_query:
|
||
|
db: "{{ koji_db_name }}"
|
||
|
login_user: "{{ koji_db_user }}"
|
||
|
login_password: "{{ koji_db_password }}"
|
||
|
login_host: "{{ koji_db_server_ip }}"
|
||
|
path_to_script: /usr/share/doc/koji/docs/schema.sql
|
||
|
when: koji_database_initialized.failed
|
||
|
|
||
|
- name: Check if Koji admin DB user exists
|
||
|
community.postgresql.postgresql_query:
|
||
|
db: "{{ koji_db_name }}"
|
||
|
login_user: "{{ koji_db_user }}"
|
||
|
login_password: "{{ koji_db_password }}"
|
||
|
login_host: "{{ koji_db_server_ip }}"
|
||
|
query: SELECT name FROM users WHERE name = %(name)s
|
||
|
named_args:
|
||
|
name: "{{ koji_admin_user }}"
|
||
|
register: koji_admin_initialized
|
||
|
|
||
|
- name: Create Koji admin DB user
|
||
|
community.postgresql.postgresql_query:
|
||
|
db: "{{ koji_db_name }}"
|
||
|
login_user: "{{ koji_db_user }}"
|
||
|
login_password: "{{ koji_db_password }}"
|
||
|
login_host: "{{ koji_db_server_ip }}"
|
||
|
query: >
|
||
|
INSERT INTO users (name, status, usertype)
|
||
|
VALUES (%(name)s, %(status)s, %(usertype)s)
|
||
|
RETURNING id
|
||
|
named_args:
|
||
|
name: "{{ koji_admin_user }}"
|
||
|
status: 0
|
||
|
usertype: 0
|
||
|
register: koji_admin_insert
|
||
|
when: koji_admin_initialized.rowcount == 0
|
||
|
|
||
|
- name: Set permissions for Koji admin DB user
|
||
|
community.postgresql.postgresql_query:
|
||
|
db: "{{ koji_db_name }}"
|
||
|
login_user: "{{ koji_db_user }}"
|
||
|
login_password: "{{ koji_db_password }}"
|
||
|
login_host: "{{ koji_db_server_ip }}"
|
||
|
query: >
|
||
|
INSERT INTO user_perms (user_id, perm_id, creator_id)
|
||
|
VALUES (%(user_id)s, 1, %(user_id)s)
|
||
|
named_args:
|
||
|
user_id: "{{ koji_admin_insert.query_result[0]['id'] }}"
|
||
|
when: koji_admin_insert.changed
|
||
|
|
||
|
- name: Configure Kerberos for Koji admin DB user
|
||
|
community.postgresql.postgresql_query:
|
||
|
db: "{{ koji_db_name }}"
|
||
|
login_user: "{{ koji_db_user }}"
|
||
|
login_password: "{{ koji_db_password }}"
|
||
|
login_host: "{{ koji_db_server_ip }}"
|
||
|
query: >
|
||
|
INSERT INTO user_krb_principals (user_id, krb_principal)
|
||
|
VALUES (%(user_id)s, %(krb_principal)s)
|
||
|
named_args:
|
||
|
user_id: "{{ koji_admin_insert.query_result[0]['id'] }}"
|
||
|
krb_principal: "{{ koji_admin_user }}@{{ koji_kerberos_realm }}"
|
||
|
when: koji_admin_insert.changed
|
||
|
|
||
|
- name: Install and configure koji-hub
|
||
|
import_tasks: koji_hub.yml
|
||
|
|
||
|
- name: Install and configure koji-web
|
||
|
import_tasks: koji_web.yml
|
||
|
|
||
|
- name: Install and configure kojira
|
||
|
import_tasks: kojira.yml
|