0

I have the following lists, generated from the output of a script.

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

I want to make use of the above output in ansible to construct and execute the following command

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

I tried using the following, but its not working.

---
- 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 }}" 

Not sure what am I doing wrong here. Any help would be much appreciated.

Muhammed Roshan
  • 81
  • 1
  • 1
  • 4
  • @techraf Could you please point me to the duplicate question? – Muhammed Roshan Apr 02 '18 at 03:26
  • I think he was referring the question in the 'linked' section of the list on the right side of this page, which seems to be [this one](https://stackoverflow.com/questions/35662388/ansible-with-items-list-of-lists-is-flattening?noredirect=1&lq=1). – Tonsic Jul 19 '19 at 18:14

1 Answers1

0

If i'm not mistaken right format of OpenShift command oc is:

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

If output of your convert_to_list.py is something like this: abc abc-display-name def def-display-name hij hij-display-name

Then try to use: - name: Framing the oc commands shell: "oc new-project {{item.split(' ')[0]}} --display-name={{item.split(' ')[1]}}" with_items: "{{ new_bu_list.stdout_lines }}"

Ripper Tops
  • 402
  • 4
  • 3