Airflow:如何从其他服务器进行SSH和运行BashOperator [英] Airflow: How to SSH and run BashOperator from a different server

查看:696
本文介绍了Airflow:如何从其他服务器进行SSH和运行BashOperator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用SSH切换到其他服务器并使用Airbnb的Airflow运行BashOperator?
我正在尝试用Airflow运行一个配置单元sql命令,但是我需要SSH到另一个机器上才能运行配置单元外壳。
我的任务应如下所示:


  1. SSH到server1

  2. 启动Hive shell

  3. 运行Hive命令

谢谢!

解决方案

我认为我已经弄清楚了:


  1. 创建一个用户界面中管理>连接下的SSH连接。注意:如果您重置数据库,连接将被删除


  2. 在Python文件中添加以下内容



    <来自airflow.contrib.hooks的pre> 导入SSHHook
    sshHook = SSHHook(conn_id =<您从UI中获得的连接ID>)


  3. 添加SSH操作员任务

      t1 = SSHExecuteOperator(
    task_id = task1,
    bash_command =< YOUR COMMAND> ;,
    ssh_hook = sshHook,
    dag = dag)


谢谢!


Is there a way to ssh to different server and run BashOperator using Airbnb's Airflow? I am trying to run a hive sql command with Airflow but I need to SSH to a different box in order to run the hive shell. My tasks should look like this:

  1. SSH to server1
  2. start Hive shell
  3. run Hive command

Thanks!

解决方案

I think that I just figured it out:

  1. Create a SSH connection in UI under Admin > Connection. Note: the connection will be deleted if you reset the database

  2. In the Python file add the following

    from airflow.contrib.hooks import SSHHook
    sshHook = SSHHook(conn_id=<YOUR CONNECTION ID FROM THE UI>)
    

  3. Add the SSH operator task

    t1 = SSHExecuteOperator(
        task_id="task1",
        bash_command=<YOUR COMMAND>,
        ssh_hook=sshHook,
        dag=dag)
    

Thanks!

这篇关于Airflow:如何从其他服务器进行SSH和运行BashOperator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆