We are using airflow as a scheduler. I want to invoke a simple bash operator in a DAG. The bash script needs password as an argument to do further processing.
How c
You can store the password in a Hook - this will be encrypted so long as you have setup your fernet key.
Here is how you can create a connection.
from airflow.models import Connection
def create_conn(username, password, host=None):
new_conn = Connection(conn_id=f'{username}_connection',
login=username,
host=host if host else None)
new_conn.set_password(password)
Then, this password is encryted in the db you setup.
To access this password:
from airflow.hooks.base_hook import BaseHook
connection = BaseHook.get_connection("username_connection")
password = connection.password # This is a getter that returns the unencrypted password.
EDIT:
There is an easier way to create a connection via the UI:
Then: