我正在尝试从 ansible 脚本运行 python 脚本。我认为这将是一件容易的事,但我无法弄清楚。我有一个这样的项目结构:
playbook-folder
roles
stagecode
files
mypythonscript.py
tasks
main.yml
release.yml
我正在尝试在 main.yml 的任务中运行 mypythonscript.py(这是 release.yml 中使用的角色)。这是任务:
- name: run my script!
command: ./roles/stagecode/files/mypythonscript.py
args:
chdir: /dir/to/be/run/in
delegate_to: 127.0.0.1
run_once: true
我也试过../files/mypythonscript.py。我认为 ansible 的路径与剧本有关,但我猜不是?
我还尝试调试以找出我在脚本中间的位置,但也没有运气。
- name: figure out where we are
stat: path=.
delegate_to: 127.0.0.1
run_once: true
register: righthere
- name: print where we are
debug: msg="{{righthere.stat.path}}"
delegate_to: 127.0.0.1
run_once: true
那只是打印出“。”。很有帮助...