[英]is there a way in ansible for my python script to get all the variables that are defined without passing them all in?
is there a way that myscript.py can have access to all these variables that my playbook has without passing them in from the command line?有没有一种方法可以让 myscript.py 访问我的剧本所具有的所有这些变量,而无需从命令行传递它们? I have a python script that requires about 30 environment variables to render a template.我有一个 python 脚本,它需要大约 30 个环境变量来呈现模板。 I cannot use jinja2 because there is a bug in jinja2 when you use sets and includes.我无法使用 jinja2,因为当您使用集合和包含时 jinja2 中存在错误。 so i had to write a script to do the work.所以我不得不编写一个脚本来完成这项工作。
- name: this is my name
script: ./roles/jboss/myscript.py --target_hostname "{{ansible_hostname}}" --role_path "{{role_path}}" --is_production "{{is_production}}" --rel_man "{{release_manifest_file}}" --rm_vendor_type "{{rm_vendor_type}}" --group_name "{{group_names}}"
args:
executable: python3
delegate_to: localhost
register: build_log_profile_output
tags: always
I cannot use jinja2 because there is a bug in jinja2 when you use sets and includes我不能使用 jinja2 因为当您使用集合和包含时 jinja2 中存在错误
sounds like your actual question, but the spirit of answering what was asked: I believe the environment is likely the shortest path from where you are to where you want to be:听起来像您的实际问题,但回答问题的精神:我相信环境可能是从您所在的地方到您想去的地方的最短路径:
- name: this is my name
script: ./roles/jboss/myscript.py
args:
executable: python3
environment:
ANSIBLE_JSON: '{{ vars | to_json }}'
delegate_to: localhost
register: build_log_profile_output
then in your script:然后在你的脚本中:
import json
import os
vars = json.loads(os.getenv('ANSIBLE_JSON'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.