Skip to content

Commit

Permalink
Removed deprecated host_vars loading & unused gitlab_api_token from…
Browse files Browse the repository at this point in the history
… deploy_vars
  • Loading branch information
AllRWeak authored and bl0way committed Feb 26, 2024
1 parent d99e495 commit cd73a3a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 51 deletions.
36 changes: 11 additions & 25 deletions nova/core/roles/deploy_vars/README.md
Original file line number Diff line number Diff line change
@@ -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
```
35 changes: 9 additions & 26 deletions nova/core/roles/deploy_vars/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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' }}"
Expand Down Expand Up @@ -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

0 comments on commit cd73a3a

Please sign in to comment.