Skip to content

Instantly share code, notes, and snippets.

@andreaschandra
Created January 9, 2022 06:39
Show Gist options
  • Save andreaschandra/4a516fe5aab02915ac2a76c481912bcf to your computer and use it in GitHub Desktop.
Save andreaschandra/4a516fe5aab02915ac2a76c481912bcf to your computer and use it in GitHub Desktop.
from datetime import datetime, timedelta
import airflow
from airflow import DAG
from airflow.operators.bash import BashOperator
dag = DAG(
dag_id="get_instance_v6",
start_date=datetime.today() - timedelta(minutes=60),
schedule_interval="*/5 * * * *",
)
get_hostname = BashOperator(
task_id=f"echo_hostname",
bash_command=(
"hostname"
),
dag=dag,
)
for i in range(10):
get_ip = BashOperator(
task_id=f"get_ip_{i}",
bash_command=(
"dig +short myip.opendns.com @resolver1.opendns.com"
),
dag=dag,
)
sleep = BashOperator(
task_id=f"sleep_{i}",
bash_command=("sleep 2"),
dag=dag
)
get_hostname >> get_ip >> sleep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment