123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- ---
- - name: Check if omnia_vault_key exists
- stat:
- path: "{{ role_path }}/../../{{ config_vaultname }}"
- register: vault_key_result
- - name: Create ansible vault key if it does not exist
- set_fact:
- vault_key: "{{ lookup('password', '/dev/null chars=ascii_letters') }}"
- when: not vault_key_result.stat.exists
- - name: Save vault key
- copy:
- dest: "{{ role_path }}/../../{{ config_vaultname }}"
- content: |
- {{ vault_key }}
- owner: root
- force: yes
- mode: '0600'
- when: not vault_key_result.stat.exists
- - name: Check if omnia config file is encrypted
- command: cat {{ role_path }}/../../{{ config_filename }}
- changed_when: false
- register: config_content
- no_log: True
- - name: Decrpyt omnia_config.yml
- command: >-
- ansible-vault decrypt {{ role_path }}/../../{{ config_filename }}
- --vault-password-file {{ role_path }}/../../{{ config_vaultname }}
- when: "'$ANSIBLE_VAULT;' in config_content.stdout"
- - name: Include variable file omnia_config.yml
- include_vars: "{{ role_path }}/../../{{ config_filename }}"
- no_log: True
- - name: Validate input parameters are not empty
- fail:
- msg: "{{ input_config_failure_msg }}"
- register: input_config_check
- when:
- - mariadb_password | length < 1 or
- k8s_version | length < 1 or
- k8s_cni | length < 1 or
- k8s_pod_network_cidr | length < 1 or
- ansible_config_file_path | length < 1
- - name: Assert mariadb_password
- assert:
- that:
- - mariadb_password | length > min_length | int - 1
- - mariadb_password | length < max_length | int + 1
- - '"-" not in mariadb_password '
- - '"\\" not in mariadb_password '
- - '"\"" not in mariadb_password '
- - " \"'\" not in mariadb_password "
- success_msg: "{{ success_msg_mariadb_password }}"
- fail_msg: "{{ fail_msg_mariadb_password }}"
- - name: Assert kubernetes version
- assert:
- that: "('1.16.7' in k8s_version) or ('1.19.3' in k8s_version)"
- success_msg: "{{ success_msg_k8s_version }}"
- fail_msg: "{{ fail_msg_k8s_version }}"
- - name: Assert kubernetes cni
- assert:
- that: "('calico' in k8s_cni) or ('flannel' in k8s_cni)"
- success_msg: "{{ success_msg_k8s_cni }}"
- fail_msg: "{{ fail_msg_k8s_cni }}"
- - name: Assert kubernetes pod network CIDR
- assert:
- that:
- - k8s_pod_network_cidr | length > 9
- - '"/" in k8s_pod_network_cidr '
- success_msg: "{{ success_msg_k8s_pod_network_cidr }}"
- fail_msg: "{{ fail_msg_k8s_pod_network_cidr }}"
- - name: Save input variables from file
- set_fact:
- db_password: "{{ mariadb_password }}"
- k8s_version: "{{ k8s_version }}"
- k8s_cni: "{{ k8s_cni }}"
- k8s_pod_network_cidr: "{{ k8s_pod_network_cidr }}"
- docker_username: "{{ docker_username }}"
- docker_password: "{{ docker_password }}"
- ansible_conf_file_path: "{{ ansible_config_file_path }}"
- no_log: True
- - name: Check whether ansible config file exists
- stat:
- path: "{{ ansible_conf_file_path }}/ansible.cfg"
- register: ansible_conf_exists
- - name: Create the directory if it does not exist
- file:
- path: "{{ ansible_conf_file_path }}"
- state: directory
- mode: "{{ file_perm }}"
- when: not ansible_conf_exists.stat.exists
- - name: Create ansible config file if it does not exist
- copy:
- dest: "{{ ansible_conf_file_path }}/ansible.cfg"
- mode: "{{ file_perm }}"
- content: |
- [defaults]
- log_path = /var/log/omnia.log
- when: not ansible_conf_exists.stat.exists
- - name: Set omnia.log file
- replace:
- path: "{{ ansible_conf_file_path }}/ansible.cfg"
- regexp: '#log_path = /var/log/ansible.log'
- replace: 'log_path = /var/log/omnia.log'
- when: ansible_conf_exists.stat.exists
- - name: Encrypt input config file
- command: >-
- ansible-vault encrypt {{ role_path }}/../../{{ config_filename }}
- --vault-password-file {{ role_path }}/../../{{ config_vaultname }}
- changed_when: false
|