Ansible Python API:如何将额外的变量传递给剧本 [英] Ansible Python API: how to pass extra vars to playbook

查看:20
本文介绍了Ansible Python API:如何将额外的变量传递给剧本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Python API 来运行一些剧本,因为我想将它与 Flash 集成以启用基于 Web 的控件.这是我的剧本(crondis.yaml):

I'm trying to use Python API to run some playbooks because I want to integrate it with Flash to enable the web-base control. Here is my playbook(crondis.yaml):

- hosts: "{{app_name}}-server"
  tasks:
    - name: disable cron
      cron:
        name: "{{app_name|upper}}_MONITOR"
        job: "/{{app_name}}/monitor.sh"
        disabled: yes

来自可以这样的cml:

From cml that can be this way:

ansible-playbook --extra-vars="{'app_name': 'newapp'}" crondis.yaml

但是在 Python API 中,我没有看到任何地方可以将变量添加到游戏中.我检查了 Variable_ManagerDataLoaderPlaybookExecutor,但没有发现任何函数可以将变量添加到播放中.如果您有任何想法,请帮我解释一下.

But in the Python API, I'm not seeing any place to add the vars to the play. I checked Variable_Manager, DataLoader and PlaybookExecutor but didn't find any function can add vars to the play. Please kindly shed a little bit light for me if you have any idea.

推荐答案

你可以通过设置 .extra_vars 属性来定义额外的变量,参见 ansible-playbook cli 代码:

You can define extra variables by setting .extra_vars property, see ansible-playbook cli code:

    # create the variable manager, which will be shared throughout
    # the code, ensuring a consistent view of global variables
    variable_manager = VariableManager()
    variable_manager.extra_vars = load_extra_vars(loader=loader, options=self.options)

这篇关于Ansible Python API:如何将额外的变量传递给剧本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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