簡體   English   中英

在Ansible playbook中激活Conda環境

[英]Activating a Conda environment in Ansible playbook

我正在嘗試運行一個需要在現有Conda環境中執行的任務列表這里運行氣流,但它可能是真的 )。

我想做這些任務:

- name: activate conda environment
 # does not work, just for the sake of understanding
 command: source activate my_conda_env

- name: initialize the database
  command: airflow initdb

- name: start the web server
  command: 'airflow webserver -p {{ airflow_webserver_port }}'

- name: start the scheduler
  command: airflow scheduler

當然,這不起作用,因為每個任務都是獨立的,並且第一個任務中的conda environment激活被以下任務忽略。

我想如果使用python virtualenv而不是conda ,問題就會一樣。

如何實現在Conda環境中運行的每個任務?

您的每個命令都將在不同的進程中執行。

另一方面, source命令用於僅將環境變量讀入當前進程(及其子進程),因此它僅適用於activate conda environment任務。

你可以嘗試做的是:

- name: initialize the database
  shell: source /full/path/to/conda/activate my_conda_env && airflow initdb
  args:
    executable: /bin/bash

- name: start the web server
  shell: 'source /full/path/to/conda/activate my_conda_env && airflow webserver -p {{ airflow_webserver_port }}'
  args:
    executable: /bin/bash

- name: start the scheduler
  shell: source /full/path/to/conda/activate my_conda_env && airflow scheduler
  args:
    executable: /bin/bash

之前,檢查在activate的目標計算機上which activate的完整路徑是什么(您需要在任何環境來源之前執行此操作)。 如果Conda安裝在用戶的空間中,則應使用相同的用戶進行Ansible連接。

正在尋找類似的東西。 找到一個比多個動作更簡潔的解決方案:

- name: Run commands in conda environment
  shell: source activate my_conda_env && airflow {{ item }}
  with_items:
    - initdb
    - webserver -p {{ airflow_webserver_port }}
    - scheduler

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM