0

We need to create a standard ansible that will change only one parameter for specific commands in a specific table

ex:

cmd: Sys; Cl; Codes; DPlan; Entry; get 1 PLO from {{ item.a }}; y
cmd: Sys; Cl; Codes; DPlan; Entry; get 1 PLO {{ item.b }} 12L; y

So I try to use the command with_item but it seems to me that my item is never defined correctly

item.a = 712
item.b = "Call Type"

I want something simple because we may have to add some of these. (item.e, item.f, .....)

Any idea?

---
- name: test
  hosts: vicky
  user: job
  become: true
  become_user: vjob

  vars_prompt:
    - name: "bwcli_username"
      prompt: "Enter your bwcli username"
      private: no

    - name: "bwcli_password"
      prompt: "Enter your bwcli password"
      private: yes

  tasks:

    - name: get table with a specific entry
      bwcli:
         admin: yes
         admin_username: "{{ bwcli_username }}"
         admin_password: "{{ bwcli_password }}"
        cmd: Sys;Cl;Codes;DPlan;Entry;get 1 PLO from {{ item.a };y;get 1 PLO from {{ item.b }};y;get 1 ICNDP {{ item.calltype }} 12L;y

      with_items:
        - { item.a: 712, item.b: "Call Type" }
vicky
  • 1
  • 1

1 Answers1

1

The conversion to item variable is done by Ansible, so each item in a list is under item.

So you need to write it like this:

with_items:
  - { a: 712, b: "Call Type" }
  - { a: 222, b: "my second item" }

Or in a visually better yaml:

with_items:
  - a: 712
    b: "Call Type"
  - a: 222
    b: "my second item"
Tahvok
  • 56
  • 4