Skip to content

Commit

Permalink
fix: factor out deployment facts (#528)
Browse files Browse the repository at this point in the history
fix: factor out deployment facts

To enable including them only in deployment, and therefore allow rendering of templates where we don't need to have all of the ansible facts related to deployment.

Reviewed-by: František Lachman <[email protected]>
  • Loading branch information
2 parents ef78237 + 8c68b58 commit a6bfdb4
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 35 deletions.
3 changes: 3 additions & 0 deletions playbooks/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
- name: Include variables
ansible.builtin.include_vars: "{{ project_dir }}/vars/{{ service }}/{{ deployment }}.yml"

- name: Include deployment facts
ansible.builtin.include_tasks: tasks/set-deployment-facts.yml

- name: Include tasks/set-facts.yml
ansible.builtin.include_tasks: tasks/set-facts.yml

Expand Down
5 changes: 5 additions & 0 deletions playbooks/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
tags:
- always

- name: Include deployment facts
ansible.builtin.include_tasks: tasks/set-deployment-facts.yml
tags:
- always

- name: Include tasks/set-facts.yml
ansible.builtin.include_tasks: tasks/set-facts.yml
tags:
Expand Down
19 changes: 19 additions & 0 deletions playbooks/render_secrets_from_templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,26 @@
---
- name: Process templates with data from extra-vars.yml
hosts: all
vars:
service: "{{ lookup('env', 'SERVICE') | default('packit', True) }}"
deployment: "{{ lookup('env', 'DEPLOYMENT') }}"
tenant: packit # MP+ tenant
tasks:
- name: Include tasks/project-dir.yml
ansible.builtin.include_tasks: tasks/project-dir.yml
tags:
- always

- name: Include variables
ansible.builtin.include_vars: "{{ project_dir }}/vars/{{ service }}/{{ deployment }}.yml"
tags:
- always

- name: Include tasks/set-facts.yml
ansible.builtin.include_tasks: tasks/set-facts.yml
tags:
- rendering-templates

- name: Include extra secret vars
ansible.builtin.include_vars:
file: "{{ path_to_secrets }}/extra-vars.yml"
Expand Down
38 changes: 38 additions & 0 deletions playbooks/tasks/set-deployment-facts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

# We call the facts deploymentconfigs even they are not DeploymentConfigs but Deployments
# because we already use the term 'deployment' for something else (prod/stg).

---
- name: Set mandatory_deploymentconfigs fact
ansible.builtin.set_fact:
mandatory_deploymentconfigs:
- postgres-{{ postgres_version }}
- redis
- packit-service
tags:
- always
- name: Set optional_deploymentconfigs fact
ansible.builtin.set_fact:
optional_deploymentconfigs:
tokman: "{{ with_tokman }}"
packit-service-fedmsg: "{{ with_fedmsg }}"
packit-service-beat: "{{ with_beat }}"
packit-dashboard: "{{ with_dashboard }}"
pushgateway: "{{ with_pushgateway }}"
nginx: "{{ with_pushgateway }}"
tags:
- always
- name: Set deploymentconfigs fact
ansible.builtin.set_fact:
# To know what DCs rollouts to wait for and also to check in tests
deploymentconfigs: '{{ mandatory_deploymentconfigs + optional_deploymentconfigs | dict2items | selectattr("value", "equalto", true) | list | map(attribute="key") | flatten }}'
tags:
- always

- name: Set flower_htpasswd_path
ansible.builtin.set_fact:
flower_htpasswd_path: "{{ path_to_secrets }}/flower-htpasswd"
tags:
- flower
36 changes: 1 addition & 35 deletions playbooks/tasks/set-facts.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

# We call the facts deploymentconfigs even they are not DeploymentConfigs but Deployments
# because we already use the term 'deployment' for something else (prod/stg).

---
- name: Set mandatory_deploymentconfigs fact
ansible.builtin.set_fact:
mandatory_deploymentconfigs:
- postgres-{{ postgres_version }}
- redis
- packit-service
tags:
- always
- name: Set optional_deploymentconfigs fact
ansible.builtin.set_fact:
optional_deploymentconfigs:
tokman: "{{ with_tokman }}"
packit-service-fedmsg: "{{ with_fedmsg }}"
packit-service-beat: "{{ with_beat }}"
packit-dashboard: "{{ with_dashboard }}"
pushgateway: "{{ with_pushgateway }}"
nginx: "{{ with_pushgateway }}"
tags:
- always
- name: Set deploymentconfigs fact
ansible.builtin.set_fact:
# To know what DCs rollouts to wait for and also to check in tests
deploymentconfigs: '{{ mandatory_deploymentconfigs + optional_deploymentconfigs | dict2items | selectattr("value", "equalto", true) | list | map(attribute="key") | flatten }}'
tags:
- always

- name: Set flower_htpasswd_path
ansible.builtin.set_fact:
flower_htpasswd_path: "{{ path_to_secrets }}/flower-htpasswd"
tags:
- flower

- name: Set managed_platform
ansible.builtin.set_fact:
managed_platform: "{{ 'api.mpp' in host }}"
Expand All @@ -48,6 +13,7 @@
with_sandbox: "{{ service == 'packit' }}"
tags:
- always

- name: Set sandbox_namespace
when: with_sandbox
tags:
Expand Down

0 comments on commit a6bfdb4

Please sign in to comment.