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

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

问题描述

我试图使用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可以这样:

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

但是在Python API中,我看不到将vars添加到剧本的任何地方.我检查了 Variable_Manager DataLoader PlaybookExecutor ,但没有发现任何可以向游戏添加var的函数. 如果您有任何想法,请为我​​提供一点启示.

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:如何将额外的var传递给剧本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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