From cd73a3ae01b8ecf1a0560d9035d2f73e72f06a3c Mon Sep 17 00:00:00 2001 From: Allar Viik Date: Mon, 26 Feb 2024 16:33:47 +0200 Subject: [PATCH] Removed deprecated host_vars loading & unused `gitlab_api_token` from deploy_vars --- nova/core/roles/deploy_vars/README.md | 36 +++++++--------------- nova/core/roles/deploy_vars/tasks/main.yml | 35 ++++++--------------- 2 files changed, 20 insertions(+), 51 deletions(-) diff --git a/nova/core/roles/deploy_vars/README.md b/nova/core/roles/deploy_vars/README.md index cb3c5683..b8549bd1 100644 --- a/nova/core/roles/deploy_vars/README.md +++ b/nova/core/roles/deploy_vars/README.md @@ -1,37 +1,23 @@ -# Role Name +# deploy_vars -COMING SOON -A brief description of the role goes here. +This role is used to set required deploy variables. Is is used as the very first role in the deploy process. By using this role, we can ensure that all required variables are set before any other roles are executed. This role also caches the required variables in a file so that they can be used by other roles. ## Requirements -COMING SOON -Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. +none ## Role Variables -COMING SOON -A description of the settable variables for this role should go here, including any variables that are in `defaults/main.yml`, `vars/main.yml`, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. +Refer to the [defaults/main.yml](https://github.com/novateams/nova.core/blob/main/nova/core/roles/deploy_vars/defaults/main.yml) file for a list and description of the variables used in this role. ## Dependencies -COMING SOON -A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. +none -## Example Playbook +## Example -COMING SOON -Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: - - - hosts: servers - roles: - - { role: username.rolename, x: 42 } - -## License - -AGPL-3.0-or-later - -## Author Information - -COMING SOON -An optional section for the role authors to include contact information, or a website (HTML is not allowed). +```yaml +- name: Including deploy_vars role... + ansible.builtin.include_role: + name: nova.core.deploy_vars +``` diff --git a/nova/core/roles/deploy_vars/tasks/main.yml b/nova/core/roles/deploy_vars/tasks/main.yml index cb5cc8e7..04387a0e 100644 --- a/nova/core/roles/deploy_vars/tasks/main.yml +++ b/nova/core/roles/deploy_vars/tasks/main.yml @@ -1,10 +1,9 @@ --- -# Using set_fact so the credentials will be looked up only once +# Setting credentials as fact because if they are in defaults Ansible will start making too many connections to Keepass and the socket will be closed - name: Setting credentials... ansible.builtin.set_fact: deployer_username: "{{ custom_deployer_username | default(lookup('keepass', (lookup('env', 'KEEPASS_DEPLOYER_CREDENTIALS_PATH')), 'username') if (lookup('env', 'KEEPASS_DEPLOYER_CREDENTIALS_PATH') | length != 0) else 'KEEPASS_DEPLOYER_CREDENTIALS_PATH not defined in .makerc-vars') }}" deployer_password: "{{ custom_deployer_password | default(lookup('keepass', (lookup('env', 'KEEPASS_DEPLOYER_CREDENTIALS_PATH')), 'password') if (lookup('env', 'KEEPASS_DEPLOYER_CREDENTIALS_PATH') | length != 0) else 'KEEPASS_DEPLOYER_CREDENTIALS_PATH not defined in .makerc-vars') }}" - gitlab_api_token: "{{ lookup('keepass', (lookup('env', 'KEEPASS_GITLAB_TOKEN')), 'password') if (lookup('env', 'KEEPASS_GITLAB_TOKEN') | length != 0) else 'KEEPASS_GITLAB_TOKEN not defined in .makerc-vars' }}" aws_access_key_id: "{{ lookup('keepass', (lookup('env', 'KEEPASS_AWS_ACCESS_KEY')), 'username') if (lookup('env', 'KEEPASS_AWS_ACCESS_KEY') | length != 0) else 'KEEPASS_AWS_ACCESS_KEY not defined in .makerc-vars' }}" aws_access_key: "{{ lookup('keepass', (lookup('env', 'KEEPASS_AWS_ACCESS_KEY')), 'password') if (lookup('env', 'KEEPASS_AWS_ACCESS_KEY') | length != 0) else 'KEEPASS_AWS_ACCESS_KEY not defined in .makerc-vars' }}" linode_api_token: "{{ lookup('keepass', (lookup('env', 'KEEPASS_LINODE_API_TOKEN')), 'password') if (lookup('env', 'KEEPASS_LINODE_API_TOKEN') | length != 0) else 'KEEPASS_LINODE_API_TOKEN not defined in .makerc-vars' }}" @@ -43,30 +42,14 @@ become: false register: host_var_present -- name: Warning but loading host_var... - when: host_var_present.stat.exists - block: - - name: WARNING - ansible.builtin.debug: - msg: | - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - Loading instance parent host variables will be deprecated on 18.12.2023. - Move the file host_vars/{{ main_id }}.yml to group_vars/{{ main_id | replace("-", "_") }}.yml to avoid this warning. - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - when: main_id | replace("-", "_") in group_names - - - name: Sleeping to read... - ansible.builtin.wait_for: - timeout: 30 - become: false - delegate_to: localhost - when: main_id | replace("-", "_") in group_names - - - name: Loading host_vars... - ansible.builtin.include_vars: - file: "{{ legacy_host_var_path }}/{{ main_id }}.yml" +- name: DEPRECATED FEATURE + ansible.builtin.fail: + msg: | + Loading instance parent host variables is deprecated. + Move the file host_vars/{{ main_id }}.yml to group_vars/{{ main_id | replace("-", "_") }}.yml to avoid this error. + when: + - host_var_present.stat.exists + - main_id | replace("-", "_") in group_names # # Uncommend to debug variables # - ansible.builtin.debug: msg="{{ }}" # - meta: end_play