[英]How do I import List of dictionaries from Python script into Ansible playbook?
[英]How do I import a python file using Ansible Playbook?
這是在 Linux 機器上。 我有一個像這樣的 run.yml
---
- name: Appspec
hosts: localhost
become: true
tasks:
- name: test 1
script: test.py
test.py 使用“import helper”的python文件(helper.py),該文件與ansible-playbook位於同一路徑,並且在運行playbook.yml時它仍然給我一個“導入錯誤:無法導入名稱助手”。 我該怎么做?
將test.py
和helper.py
復制到遠程機器上的同一目錄(可能到臨時目錄)並運行python test.py
作為command
任務。 像這樣的東西:
- name: Create temporary directory
tempfile:
state: directory
register: tmpdir
- name: Copy test.py
copy:
src: /wherever/test.py
dest: "{{tmpdir.path}}/test.py"
- name: Copy helper.py
copy:
src: /wherever/helper.py
dest: "{{tmpdir.path}}/helper.py"
- name: Run test.py
command: python test.py
args:
chdir: "{{tmpdir.path}}"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.