Skip to content

Commit

Permalink
updating airflow vars & conns task to delete select variables being u…
Browse files Browse the repository at this point in the history
…pdated
  • Loading branch information
cmharlow committed Apr 10, 2019
1 parent 561620e commit ffbe2ba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
10 changes: 6 additions & 4 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,14 @@ airflow_webserver_admins:
airflow_dummy_password: "dummy-password"

# Connections management
airflow_drop_existing_connections_before_add: True
airflow_connections: []
airflow_connections:
- conn_id: "ANSIBLE_TEST"
conn_uri: "http://localhost:9999"

# Variables management
airflow_drop_existing_variables_before_add: True
airflow_variables: []
airflow_variables:
- key: "ANSIBLE_TEST"
value: "test_value"

# Logrotate configuration
airflow_logrotate_config:
Expand Down
8 changes: 4 additions & 4 deletions tasks/manage_airflow_variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@


# Only add and delete actions are managed, not update
- name: 'CONFIG | VARIABLES | Remove existing variables'
- name: 'CONFIG | VARIABLES | Remove listed variables'
command: >
{{ airflow_virtualenv }}/bin/airflow variables --delete {{ item }}
{{ airflow_virtualenv }}/bin/airflow variables --delete {{ item.key }}
changed_when: false
with_items: "{{ airflow_existing_variables.stdout_lines }}"
when: 'airflow_drop_existing_variables_before_add | bool'
with_items: "{{ airflow_variables }}"
when: 'item.key in airflow_existing_variables.stdout_lines'


- name: 'CONFIG | VARIABLES | Add variables'
Expand Down
10 changes: 5 additions & 5 deletions tasks/manage_connections.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@


# Only add and delete actions are managed, not update
- name: 'CONFIG | CONNECTIONS | Remove existing connections'
- name: 'CONFIG | CONNECTIONS | Remove listed connections'
command: >
{{ airflow_virtualenv }}/bin/airflow connections --delete --conn_id {{ item }}
{{ airflow_virtualenv }}/bin/airflow connections --delete --conn_id {{ item.conn_id }}
changed_when: false
with_items: "{{ airflow_existing_connections.stdout_lines }}"
when: 'airflow_drop_existing_connections_before_add | bool'
with_items: "{{ airflow_connections }}"
when: 'item.conn_id in airflow_existing_connections.stdout_lines'


- name: 'CONFIG | CONNECTIONS | Add connections without extra settings'
Expand All @@ -31,7 +31,7 @@
changed_when: false
no_log: True
with_items: "{{ airflow_connections }}"
when: "(item.conn_extra | default('')) | length = 0"
when: "(item.conn_extra | default('')) | length == 0"


- name: 'CONFIG | CONNECTIONS | Add connections with extra settings'
Expand Down

0 comments on commit ffbe2ba

Please sign in to comment.