๐Ÿ“— Ansible playbooks and roles for building an idempotent, interconnected and scalable infrastructure
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.
 
 
ansible-playbooks/tasks/pre_tasks.yml

63 lines
2.8 KiB

- name: determine host info
set_fact:
host_name: "{{ actual_hostname | d(inventory_hostname) }}"
host_tld: "{%- if branch is defined -%}{{ branch }}.{%- endif -%}{{ tld if (use_external_tld | d(false) == true) else int_tld }}"
host_tls: "{{ use_tls | d(true) }}"
host_protocol: "{{ 'https' if (use_tls | d(true)) else 'http' }}"
host_metrics: "{{ services.prometheus is defined and (use_metrics | d(true) == true) }}"
host_mail: "{{ mail_server.mta_hostname is defined and (use_mail | d(true) == true) }}"
host_backups: "{{ services.backup is defined and (use_backups | d(true) == true) }}"
- name: determine host fqdn and uri
set_fact:
host_fqdn: "{{ host_name ~ '.' ~ host_tld }}"
host_url: "{{ host_protocol }}://{{ host_name ~ '.' ~ host_tld }}"
- name: define ansible_host if it is missing
set_fact:
ansible_host: "{{ host_fqdn }}"
when: ansible_host is not defined
- name: select a cluster node
include_tasks: tasks/select_node.yml
when: "'containers' in group_names"
- name: set hardware information
set_fact:
hardware: "{{ default_container_hardware | combine(role_hardware[host_primary_role] | d({})) |
combine((container_hardware if 'containers' in group_names else host_hardware) | d({})) }}"
- name: clamp hardware cores to max node number
set_fact:
hardware: "{{ hardware | combine({'cores': ([hardware.cores, hostvars[selected_node]['max_cores'] | d(hardware.cores)] | min)}) }}"
when: "not ('containers' in group_names) and (selected_node is defined) and (hostvars[selected_node]['max_cores'] is defined)"
- block:
- name: validate database parameters
fail:
msg: some database parameters are not defined or invalid
when: (database.name is not string) or
(database.user is defined and database.user is not string) or
(database.pass is defined and database.pass is not string) or
(database.host is defined and database.host is not string) or
(database.self_hosted is defined and database.self_hosted is not boolean)
- name: set database information
set_fact:
database_name: "{{ database.name | mandatory }}"
database_user: "{{ database.user | d(database.name) }}"
database_pass: "{{ database.pass }}"
database_host: "{{ '127.0.0.1' if (database.self_hosted | d(false) == true) or (services.db is not defined) else
(services.db.address | d(hostvars[services.db.hostname]['ansible_host'])) }}"
database_hostname: "{{ inventory_hostname if (database.self_hosted | d(false) == true) or (services.db is not defined) else
services.db.hostname }}"
database_self_hosted: "{{ (database.self_hosted | d(false) == true) or (services.db is not defined) }}"
when: database is mapping