0

i would like to print the value of variable 'varB' from the board tab1. i assume that 'inventory_hostname' is variable from inventory and pass DEBIAN1

ansible-inventory --list

...
"_meta": {
        "hostvars": {
            "DEBIAN1": {
                "var0": true,
                "tab1": [
                {
                    "varA": "toto",
                    "varB": "titi"
                }
    ],
...

My playbook:

tasks:
    - name: TEST1
      debug:
        msg: "print me this {{ hostvars[inventory_hostname].tab1[.varB] }}"

The result is always FAILED... Couls you help me for this code... I m looking for a solution for 2 days...

bacup
  • 1
  • `[ ]` indicates a list in JSON, so you need to select the element of the list before addressing `varB`. – techraf Jun 02 '18 at 09:44
  • That said, you seem to have more elements in `tab1` as indicated by `],`, so [this answer](https://stackoverflow.com/a/31896249/2947502) might also be a fit for duplicate. It is unclear what you really want to achieve. – techraf Jun 02 '18 at 10:08
  • yes but in my example i juste want ta have the result 'titi'. In other word all the string in "varB" variable. Is it possible ? – bacup Jun 02 '18 at 10:17
  • Yes. Choose appropriate method from the answers I linked to. – techraf Jun 02 '18 at 13:26

0 Answers0