Skip to content

Commit

Permalink
Merge pull request #12 from usegalaxy-au/refactor-env-vars
Browse files Browse the repository at this point in the history
Consolidate walle_env_vars
  • Loading branch information
neoformit authored Nov 6, 2024
2 parents aa04558 + dda7815 commit 5771851
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 60 deletions.
71 changes: 28 additions & 43 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,45 @@ walle_script_location: /usr/local/bin/walle.py
walle_filesize_min: 0
walle_filesize_max: 10
walle_since_hours: 24
walle_envs_database:
- key: MALWARE_LIB
value: "{{ walle_malware_database_location }}/{{ walle_database_file }}"
- key: PGPASSFILE
value: "{{ walle_pgpass_file }}"
- key: GALAXY_CONFIG_FILE
value: "{{ galaxy_config_dir }}/galaxy.yml"
- key: GALAXY_LOG_DIR
value: "{{ galaxy_log_dir }}"
- key: PGHOST
value: 127.0.0.1
- key: PGUSER
value: galaxy
- key: PGDATABASE
value: galaxy
- key: GALAXY_PULSAR_APP_CONF
value: "{{ galaxy_config_dir }}/pulsar_app.yml"
- key: GXADMIN_PATH
value: /usr/local/bin/gxadmin

# These will be added to the default env vars - you can override
# walle_envs_database by defining the same key in walle_extra_env_vars
walle_extra_env_vars: []
walle_verbose: false
walle_kill: false
# walle_tool: <string to filter tool ids in database job table>

walle_env_vars: "{{ walle_envs_database + walle_extra_env_vars }}"
walle_envs_database:
MALWARE_LIB: "{{ walle_malware_database_location }}/{{ walle_database_file }}"
PGPASSFILE: "{{ walle_pgpass_file }}"
GALAXY_CONFIG_FILE: "{{ galaxy_config_dir }}/galaxy.yml"
GALAXY_LOG_DIR: "{{ galaxy_log_dir }}"
PGHOST: 127.0.0.1
PGUSER: galaxy
PGDATABASE: galaxy
GALAXY_PULSAR_APP_CONF: "{{ galaxy_config_dir }}/pulsar_app.yml"
GXADMIN_PATH: /usr/local/bin/gxadmin

# delete users when malware was found and malware severity reached walle_delete_threshold
walle_api_key: null # admin api key to delete users, goes to VAULT
walle_galaxy_url: null # galaxy_hostname, no leading slash
walle_delete_users: false
walle_delete_threshold: medium
walle_envs_user_deletion:
- key: GALAXY_API_KEY
value: "{{ walle_api_key }}"
- key: GALAXY_BASE_URL
value: "{{ walle_galaxy_url }}"
# - key: GALAXY_USER_DELETION_MESSAGE
# value: "Your personalized message"
# - key: GALAXY_USER_DELETION_SUBJECT
# value: "Your personalized subject line"
# walle_api_key: #admin api key to delete users, goes to VAULT
# walle_galaxy_url: #galaxy_hostname, no leading slash
# walle_tool: <string to filter tool ids in database job table>
walle_verbose: false
walle_kill: false
GALAXY_API_KEY: "{{ walle_api_key }}"
GALAXY_BASE_URL: "{{ walle_galaxy_url }}"
# GALAXY_USER_DELETION_MESSAGE: "Your personalized message"
# GALAXY_USER_DELETION_SUBJECT: "Your personalized subject line"

walle_slack_alerts: false
walle_slack_api_token: null # Make a "Slack app" to get a token
walle_slack_channel_id: null # Copy from your Slack channel settings
walle_envs_slack:
- key: SLACK_API_TOKEN
value: "{{ walle_slack_api_token }}"
- key: SLACK_CHANNEL_ID
value: "{{ walle_slack_channel_id }}"
- key: WALLE_HOSTNAME
value: "{{ inventory_hostname }}"
SLACK_API_TOKEN: "{{ walle_slack_api_token }}"
SLACK_CHANNEL_ID: "{{ walle_slack_channel_id }}"
WALLE_HOSTNAME: "{{ inventory_hostname }}"

walle_env_vars: "{{ walle_envs_database | combine(walle_envs_user_deletion) | combine(walle_envs_slack) }}"

# These will be added to the default env vars - you can override
# defaults by defining the same key in walle_extra_env_vars
walle_extra_env_vars: {}

# Cron
walle_cron_day: "*"
Expand Down
22 changes: 5 additions & 17 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,16 @@
path: "{{ walle_bashrc }}"
state: touch

- name: Add env variables to WallE .bashrc
ansible.builtin.lineinfile:
path: "{{ walle_bashrc }}"
regexp: "^export {{ item.key }}="
line: 'export {{ item.key }}="{{ item.value }}"'
with_items: "{{ walle_env_vars }}"
- name: Extend walle_env_vars with user-defined walle_extra_env_vars
ansible.builtin.set_fact:
walle_env_vars: "{{ walle_env_vars | combine(walle_extra_env_vars) }}"

- name: Add env variables for user deletion (WallE)
- name: Add walle_env_vars to walle_bashrc
ansible.builtin.lineinfile:
path: "{{ walle_bashrc }}"
regexp: "^export {{ item.key }}="
line: 'export {{ item.key }}="{{ item.value }}"'
with_items: "{{ walle_envs_user_deletion }}"
when: walle_delete_users
with_dict: "{{ walle_env_vars }}"

- name: Copy galaxy_jwd.py script to walle_script_location

Check warning on line 45 in tasks/main.yml

View workflow job for this annotation

GitHub Actions / super-linter

jinja[spacing]

Jinja2 spacing could be improved: {{ walle_script_location|dirname }}/galaxy_jwd.py -> {{ walle_script_location | dirname }}/galaxy_jwd.py
ansible.builtin.copy:
Expand All @@ -54,14 +50,6 @@
owner: "{{ walle_user_name }}"
group: "{{ walle_user_group }}"

- name: Add env variables for slack notifications (WallE)
ansible.builtin.lineinfile:
path: "{{ walle_bashrc }}"
regexp: "^export {{ item.key }}="
line: 'export {{ item.key }}="{{ item.value }}"'
with_items: "{{ walle_envs_slack }}"
when: walle_slack_alerts

- name: Create logfile (WallE)
ansible.builtin.file:
state: touch
Expand Down

0 comments on commit 5771851

Please sign in to comment.