Skip to content

Commit

Permalink
Default conn_extra to {} (#58)
Browse files Browse the repository at this point in the history
* Try omit

* to_json or omit

* Try None as default

* Try default last

* Try length

* set default then check length

* Use {} as default
  • Loading branch information
sensei100 authored Jul 10, 2021
1 parent e4f2289 commit 3d54779
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tasks/manage_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
- name: 'CONFIG | Manage database initialize'
become_user: "{{ airflow_user_name }}"
become: true
command: "{{ airflow_virtualenv }}/bin/airflow initdb"
command: "{{ airflow_virtualenv }}/bin/airflow db init"
run_once: true
when:
- "not airflow_config_stat.stat.exists"
Expand Down
19 changes: 13 additions & 6 deletions tasks/manage_connections.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
register: 'airflow_existing_connections'
args:
executable: /bin/bash
tags:
- connections


# Only add and delete actions are managed, not update
Expand All @@ -24,19 +26,21 @@
no_log: true
with_items: "{{ airflow_connections }}"
when: 'item.conn_id in airflow_existing_connections.stdout_lines'

tags:
- connections

- name: 'CONFIG | CONNECTIONS | Add connections using conn_uri'
command: >
{{ airflow_virtualenv }}/bin/airflow connections --add \
--conn_id {{ item.conn_id }} \
--conn_uri {{ item.conn_uri | default("") | quote }} \
--conn_extra '{{ item.conn_extra | to_json }}'
--conn_extra '{{ item.conn_extra | default({}) | to_json }}'
changed_when: false
no_log: true
with_items: "{{ airflow_connections }}"
when: "(item.conn_uri | default('')) | length > 0"

tags:
- connections

- name: 'CONFIG | CONNECTIONS | Add connections not using conn_uri without port'
command: >
Expand All @@ -47,14 +51,15 @@
--conn_login {{ item.conn_login | default("") | quote }} \
--conn_password {{ item.conn_password | default("") | quote }} \
--conn_schema {{ item.conn_schema | default("") | quote }} \
--conn_extra '{{ item.conn_extra | to_json }}'
--conn_extra '{{ item.conn_extra | default({}) | to_json }}'
changed_when: false
no_log: true
with_items: "{{ airflow_connections }}"
when:
- "(item.conn_uri | default('')) | length == 0"
- "(item.conn_port | default(0)) | int == 0"

tags:
- connections

- name: 'CONFIG | CONNECTIONS | Add connections not using conn_uri with port'
command: >
Expand All @@ -66,10 +71,12 @@
--conn_password {{ item.conn_password | default("") | quote }} \
--conn_schema {{ item.conn_schema | default("") | quote }} \
--conn_port {{ item.conn_port }} \
--conn_extra '{{ item.conn_extra | to_json }}'
--conn_extra '{{ item.conn_extra | default({}) | to_json }}'
changed_when: false
no_log: true
with_items: "{{ airflow_connections }}"
when:
- "(item.conn_uri | default('')) | length == 0"
- "(item.conn_port | default(0)) | int > 0"
tags:
- connections

0 comments on commit 3d54779

Please sign in to comment.