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.
149 lines
4.7 KiB
149 lines
4.7 KiB
---
|
|
- 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: Check if /usr/share/doc/koji/docs/schema.sql file exists
|
|
ansible.builtin.stat:
|
|
path: /usr/share/doc/koji/docs/schema.sql
|
|
register: koji_docs_schema_result
|
|
|
|
- name: Initialize Koji database from /usr/share/doc/koji/docs/schema.sql
|
|
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 and koji_docs_schema_result.stat.exists
|
|
|
|
- name: Initialize Koji database from /usr/share/koji/schema.sql
|
|
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/koji/schema.sql
|
|
when: koji_database_initialized.failed and not koji_docs_schema_result.stat.exists
|
|
|
|
- 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
|
|
|
|
- name: Add Koji builders
|
|
block:
|
|
- name: Obtain Koji admin kerberos ticket
|
|
ansible.builtin.shell: "echo '{{ koji_admin_password }}' | kinit {{ koji_admin_principal }}"
|
|
changed_when: False
|
|
|
|
- include: koji_add_host.yml
|
|
vars:
|
|
koji_build_host: "{{ item }}"
|
|
koji_build_host_createrepo: true
|
|
with_items: "{{ koji_builders }}"
|
|
always:
|
|
- name: Destroy Koji admin kerberos ticket
|
|
ansible.builtin.command: "kdestroy -p {{ koji_admin_principal }}"
|
|
ignore_errors: true
|
|
changed_when: False
|
|
when: koji_builders
|