๐Ÿ“— 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

81 lines
3.1 KiB

- name: set host name
2 years ago
set_fact:
host_name: "{{ inventory_hostname }}"
when: host_name is not defined
2 years ago
- name: set host tld
set_fact:
host_tld: "{{ ((host_branch ~ '.') if host_branch is defined else '') ~ (tld if (host_external_tld | d(false) == true) else int_tld) }}"
when: host_tld is not defined
- name: set host tls
set_fact:
host_tls: yes
when: host_tls is not defined
- name: set other host variables
set_fact:
host_protocol: "{{ 'https' if host_tls else 'http' }}"
host_metrics: "{{ services.prometheus is defined and (host_metrics | d(true) == true) }}"
host_mail: "{{ mail_server.mta_hostname is defined and (host_mail | d(true) == true) }}"
host_backups: "{{ services.backup is defined and (host_backups | d(true) == true) }}"
host_is_container: "{{ ('containers' in group_names) or (host_is_container | d(false) == true) }}"
- name: set host fqdn and uri
2 years ago
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: host_is_container
2 years ago
- name: set hardware information
set_fact:
host_hardware: "{{ (default_container_hardware | combine(role_hardware | d({})) |
combine(host_hardware | d({}))) if host_is_container
else (host_hardware | d({})) }}"
2 years ago
- name: clamp hardware cores to max node number
set_fact:
host_hardware: "{{ host_hardware | combine({'cores': ([host_hardware.cores, hostvars[selected_node]['max_cores'] | d(host_hardware.cores)] | min)}) }}"
when: "host_is_container and (selected_node is defined) and (hostvars[selected_node]['max_cores'] is defined)"
2 years ago
- 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