【问题标题】:Ansible - How to generate a command from multiple lines of lists? [duplicate]Ansible - 如何从多行列表生成命令? [复制]
【发布时间】:2018-04-01 15:49:58
【问题描述】:

我有以下列表,从脚本的输出生成。

 ['abc', 'abc-display-name']
 ['def', 'def-display-name']
 ['hij', 'hij-display-name']

我想在ansible中利用上面的输出来构造和执行下面的命令

oc create project -n abc -d abc-display-name

我尝试使用以下方法,但它不起作用。

---
- hosts: localhost
  gather_facts: no
  tasks:
    - name: Executing the python script
      script: convert_to_list.py
      register: new_bu_list

    - name: Framing the oc commands
      shell: "oc create project -n {{item[0]}} -d {{item[1]}}"
      with_lines: "{{ new_bu_list.stdout_lines }}" 

不知道我在这里做错了什么。任何帮助将非常感激。

【问题讨论】:

  • @techraf 你能指出重复的问题吗?
  • 我认为他指的是此页面右侧列表的“链接”部分中的问题,似乎是this one

标签: ansible


【解决方案1】:

如果我没记错的话,OpenShift 命令oc 的正确格式是:

oc new-project abc --display-name='abc-display-name'

如果您的convert_to_list.py 的输出是这样的: abc abc-display-name def def-display-name hij hij-display-name

然后尝试使用: - name: Framing the oc commands shell: "oc new-project {{item.split(' ')[0]}} --display-name={{item.split(' ')[1]}}" with_items: "{{ new_bu_list.stdout_lines }}"

【讨论】:

  • 我用“-debug: msg”试了一下,我得到了下面的`fatal: [localhost]: FAILED! => {"msg": "lookup_plugin.lines(abc abc-display-name) 返回 127"}`
  • 你可以试试with_lines 吗?
猜你喜欢
  • 2011-06-03
  • 1970-01-01
  • 2011-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-11
相关资源
最近更新 更多