0

In Ansible,I am using REST API...I want value of clientid from below code and want to use it in another task..I am using ansible uri module.

 debug: var=clients.json.clientProperties[3].client.clientEntity.clientId
      when: name==clients.json.clientProperties[{{ item }}].client.clientEntity.clientName
      with_sequence: start=0 end={{clients.json.clientProperties|length-1}}

I want to store "16" in one variable and need to pass another url

piyushj
  • 1,546
  • 5
  • 21
  • 29
Dipali
  • 1

1 Answers1

0
- debug: var=clients.json.clientProperties[3].client.clientEntity.clientId
  when: name == clients.json.clientProperties[ item ].client.clientEntity.clientName
  with_sequence: start=0 end="{{clients.json.clientProperties|length-1}}"
  register: result

The vars you are looking for will be available at result.results[].item. You can loop over result.results or access the results individually with result.results[0], result.results[1], etc.

MillerGeek
  • 3,057
  • 20
  • 23
  • Can you please elaborate it. Here In our code when name matches with clientname I want to store value of clientId. I don't want whole json array file. – Dipali Sep 27 '16 at 05:23
  • Without more context I'm not sure I can give a better answer because you are doing this in a loop. You can't save multiple values to the same var except as a list as I'm doing here, meaning you could overwrite a value you want before you can use it. – MillerGeek Sep 27 '16 at 05:50
  • copy: content={{clients.json.clientProperties[3].client.clientEntity.clientId}} dest="/tmp/result.txt" when: name==clients.json.clientProperties[{{ item }}].client.clientEntity.clientName with_sequence: start=0 end={{clients.json.clientProperties|length-1}} – Dipali Sep 27 '16 at 08:16
  • here in copy content I am manually passing [3] but I want to pass item instead of [3]...But it is giving {"failed": true, "msg": "template error while templating string: expected token ':', got '}' – Dipali Sep 27 '16 at 08:17