Ansible loop over dictionariesHow to loop over this dictionary in Ansible?Ansible - How to use register name from with_itemsAnsible fileinline not working with loopAnsible passing variables to rolesAnsible Script Module Not Interpreting VariableAnsible with_items conditional check against jsonGetting value undefined error in ansibleAnsible with “Alternative Directory Layout” and using vaultsAnsible v2.2 error when using with_subelements which worked fine in 1.7ansible docker mount multiple portHow to store IP of EC2 instance in hosts file using Ansible?

Has any country ever had 2 former presidents in jail simultaneously?

How can I write humor as character trait?

Which Article Helped Get Rid of Technobabble in RPGs?

What are some good ways to treat frozen vegetables such that they behave like fresh vegetables when stir frying them?

How do you make your own symbol when Detexify fails?

Is there a RAID 0 Equivalent for RAM?

How do I tell my boss that I'm quitting soon, especially given that a colleague just left this week

A variation to the phrase "hanging over my shoulders"

Doesn't the system of the Supreme Court oppose justice?

What is the highest possible scrabble score for placing a single tile

Can I turn my anal-retentiveness into a career?

How does electrical safety system work on ISS?

How to get directions in deep space?

Is there a nicer/politer/more positive alternative for "negates"?

Why do Radio Buttons not fill the entire outer circle?

Do we have to expect a queue for the shuttle from Watford Junction to Harry Potter Studio?

"It doesn't matter" or "it won't matter"?

What (the heck) is a Super Worm Equinox Moon?

What does Apple's new App Store requirement mean

Which was the first story featuring espers?

awk assign to multiple variables at once

How much theory knowledge is actually used while playing?

Permission on Database

How to make money from a browser who sees 5 seconds into the future of any web page?



Ansible loop over dictionaries


How to loop over this dictionary in Ansible?Ansible - How to use register name from with_itemsAnsible fileinline not working with loopAnsible passing variables to rolesAnsible Script Module Not Interpreting VariableAnsible with_items conditional check against jsonGetting value undefined error in ansibleAnsible with “Alternative Directory Layout” and using vaultsAnsible v2.2 error when using with_subelements which worked fine in 1.7ansible docker mount multiple portHow to store IP of EC2 instance in hosts file using Ansible?













0















I was trying to loop over dictionaries and I referred the following thread but it kept on failing:



How to loop over this dictionary in Ansible?



Following is my play book:



- hosts: server_hosts
tasks:
- name: Include dictionary data
include_vars:
file: vars/input_vars.yaml
- name: Show info field from data.yml
debug:
msg: "Id: input_data[item]['version'] - info: input_data[item]['name'] "
with_items: " input_data.keys() "


Following is my dictionary vars/input_vars.yaml file:



input_data:

item_1:

name: "test1"

version: "18.3"

item_2:

name: "test2"

version: "18.3"
item_3:

name: "test3"

version: "18.3"


When I executed the playbook, it fails with following error:



fatal: [192.168.16.120]: FAILED! => 
"ansible_facts": ,
"ansible_included_var_files": [],
"changed": false,
"message": "Syntax Error while loading YAML.n mapping values are not allowed herennThe error appears to have been in '/git_projects/base/vars/input_vars.yaml': line 2, column 12, but maynbe elsewhere in the file depending on the exact syntax problem.nnThe offending line appears to be:nn----n input_data:n ^ heren"










share|improve this question


























    0















    I was trying to loop over dictionaries and I referred the following thread but it kept on failing:



    How to loop over this dictionary in Ansible?



    Following is my play book:



    - hosts: server_hosts
    tasks:
    - name: Include dictionary data
    include_vars:
    file: vars/input_vars.yaml
    - name: Show info field from data.yml
    debug:
    msg: "Id: input_data[item]['version'] - info: input_data[item]['name'] "
    with_items: " input_data.keys() "


    Following is my dictionary vars/input_vars.yaml file:



    input_data:

    item_1:

    name: "test1"

    version: "18.3"

    item_2:

    name: "test2"

    version: "18.3"
    item_3:

    name: "test3"

    version: "18.3"


    When I executed the playbook, it fails with following error:



    fatal: [192.168.16.120]: FAILED! => 
    "ansible_facts": ,
    "ansible_included_var_files": [],
    "changed": false,
    "message": "Syntax Error while loading YAML.n mapping values are not allowed herennThe error appears to have been in '/git_projects/base/vars/input_vars.yaml': line 2, column 12, but maynbe elsewhere in the file depending on the exact syntax problem.nnThe offending line appears to be:nn----n input_data:n ^ heren"










    share|improve this question
























      0












      0








      0








      I was trying to loop over dictionaries and I referred the following thread but it kept on failing:



      How to loop over this dictionary in Ansible?



      Following is my play book:



      - hosts: server_hosts
      tasks:
      - name: Include dictionary data
      include_vars:
      file: vars/input_vars.yaml
      - name: Show info field from data.yml
      debug:
      msg: "Id: input_data[item]['version'] - info: input_data[item]['name'] "
      with_items: " input_data.keys() "


      Following is my dictionary vars/input_vars.yaml file:



      input_data:

      item_1:

      name: "test1"

      version: "18.3"

      item_2:

      name: "test2"

      version: "18.3"
      item_3:

      name: "test3"

      version: "18.3"


      When I executed the playbook, it fails with following error:



      fatal: [192.168.16.120]: FAILED! => 
      "ansible_facts": ,
      "ansible_included_var_files": [],
      "changed": false,
      "message": "Syntax Error while loading YAML.n mapping values are not allowed herennThe error appears to have been in '/git_projects/base/vars/input_vars.yaml': line 2, column 12, but maynbe elsewhere in the file depending on the exact syntax problem.nnThe offending line appears to be:nn----n input_data:n ^ heren"










      share|improve this question














      I was trying to loop over dictionaries and I referred the following thread but it kept on failing:



      How to loop over this dictionary in Ansible?



      Following is my play book:



      - hosts: server_hosts
      tasks:
      - name: Include dictionary data
      include_vars:
      file: vars/input_vars.yaml
      - name: Show info field from data.yml
      debug:
      msg: "Id: input_data[item]['version'] - info: input_data[item]['name'] "
      with_items: " input_data.keys() "


      Following is my dictionary vars/input_vars.yaml file:



      input_data:

      item_1:

      name: "test1"

      version: "18.3"

      item_2:

      name: "test2"

      version: "18.3"
      item_3:

      name: "test3"

      version: "18.3"


      When I executed the playbook, it fails with following error:



      fatal: [192.168.16.120]: FAILED! => 
      "ansible_facts": ,
      "ansible_included_var_files": [],
      "changed": false,
      "message": "Syntax Error while loading YAML.n mapping values are not allowed herennThe error appears to have been in '/git_projects/base/vars/input_vars.yaml': line 2, column 12, but maynbe elsewhere in the file depending on the exact syntax problem.nnThe offending line appears to be:nn----n input_data:n ^ heren"







      ansible






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 23:42









      drifterdrifter

      103




      103






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I have tested it and it works, I have removed extra newlines from input_vars.yaml



          ➜ ~ cat input_vars.yaml 
          input_data:
          item_1:
          name: "test1"
          version: "18.3"
          item_2:
          name: "test2"
          version: "18.3"
          item_3:
          name: "test3"
          version: "18.3"

          ➜ ~ cat example.yml
          ---
          - hosts: localhost
          tasks:
          - name: Include dictionary data
          include_vars:
          file: input_vars.yaml
          - name: Show info field from data.yml
          debug:
          msg: "Id: input_data[item]['version'] - info: input_data[item]['name'] "
          with_items: " input_data.keys() "


          Output



          ➜ ~ ansible-playbook example.yml 
          [WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

          [WARNING]: No inventory was parsed, only implicit localhost is available

          [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


          PLAY [localhost] ***********************************************************************************************************************

          TASK [Gathering Facts] *****************************************************************************************************************
          ok: [localhost]

          TASK [Include dictionary data] *********************************************************************************************************
          ok: [localhost]

          TASK [Show info field from data.yml] ***************************************************************************************************
          ok: [localhost] => (item=item_2) =>
          "msg": "Id: 18.3 - info: test2"

          ok: [localhost] => (item=item_3) =>
          "msg": "Id: 18.3 - info: test3"

          ok: [localhost] => (item=item_1) =>
          "msg": "Id: 18.3 - info: test1"


          PLAY RECAP *****************************************************************************************************************************
          localhost : ok=3 changed=0 unreachable=0 failed=0





          share|improve this answer























          • Thanks. You are right, it worked.

            – drifter
            Mar 8 at 0:26










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054586%2fansible-loop-over-dictionaries%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          I have tested it and it works, I have removed extra newlines from input_vars.yaml



          ➜ ~ cat input_vars.yaml 
          input_data:
          item_1:
          name: "test1"
          version: "18.3"
          item_2:
          name: "test2"
          version: "18.3"
          item_3:
          name: "test3"
          version: "18.3"

          ➜ ~ cat example.yml
          ---
          - hosts: localhost
          tasks:
          - name: Include dictionary data
          include_vars:
          file: input_vars.yaml
          - name: Show info field from data.yml
          debug:
          msg: "Id: input_data[item]['version'] - info: input_data[item]['name'] "
          with_items: " input_data.keys() "


          Output



          ➜ ~ ansible-playbook example.yml 
          [WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

          [WARNING]: No inventory was parsed, only implicit localhost is available

          [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


          PLAY [localhost] ***********************************************************************************************************************

          TASK [Gathering Facts] *****************************************************************************************************************
          ok: [localhost]

          TASK [Include dictionary data] *********************************************************************************************************
          ok: [localhost]

          TASK [Show info field from data.yml] ***************************************************************************************************
          ok: [localhost] => (item=item_2) =>
          "msg": "Id: 18.3 - info: test2"

          ok: [localhost] => (item=item_3) =>
          "msg": "Id: 18.3 - info: test3"

          ok: [localhost] => (item=item_1) =>
          "msg": "Id: 18.3 - info: test1"


          PLAY RECAP *****************************************************************************************************************************
          localhost : ok=3 changed=0 unreachable=0 failed=0





          share|improve this answer























          • Thanks. You are right, it worked.

            – drifter
            Mar 8 at 0:26















          0














          I have tested it and it works, I have removed extra newlines from input_vars.yaml



          ➜ ~ cat input_vars.yaml 
          input_data:
          item_1:
          name: "test1"
          version: "18.3"
          item_2:
          name: "test2"
          version: "18.3"
          item_3:
          name: "test3"
          version: "18.3"

          ➜ ~ cat example.yml
          ---
          - hosts: localhost
          tasks:
          - name: Include dictionary data
          include_vars:
          file: input_vars.yaml
          - name: Show info field from data.yml
          debug:
          msg: "Id: input_data[item]['version'] - info: input_data[item]['name'] "
          with_items: " input_data.keys() "


          Output



          ➜ ~ ansible-playbook example.yml 
          [WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

          [WARNING]: No inventory was parsed, only implicit localhost is available

          [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


          PLAY [localhost] ***********************************************************************************************************************

          TASK [Gathering Facts] *****************************************************************************************************************
          ok: [localhost]

          TASK [Include dictionary data] *********************************************************************************************************
          ok: [localhost]

          TASK [Show info field from data.yml] ***************************************************************************************************
          ok: [localhost] => (item=item_2) =>
          "msg": "Id: 18.3 - info: test2"

          ok: [localhost] => (item=item_3) =>
          "msg": "Id: 18.3 - info: test3"

          ok: [localhost] => (item=item_1) =>
          "msg": "Id: 18.3 - info: test1"


          PLAY RECAP *****************************************************************************************************************************
          localhost : ok=3 changed=0 unreachable=0 failed=0





          share|improve this answer























          • Thanks. You are right, it worked.

            – drifter
            Mar 8 at 0:26













          0












          0








          0







          I have tested it and it works, I have removed extra newlines from input_vars.yaml



          ➜ ~ cat input_vars.yaml 
          input_data:
          item_1:
          name: "test1"
          version: "18.3"
          item_2:
          name: "test2"
          version: "18.3"
          item_3:
          name: "test3"
          version: "18.3"

          ➜ ~ cat example.yml
          ---
          - hosts: localhost
          tasks:
          - name: Include dictionary data
          include_vars:
          file: input_vars.yaml
          - name: Show info field from data.yml
          debug:
          msg: "Id: input_data[item]['version'] - info: input_data[item]['name'] "
          with_items: " input_data.keys() "


          Output



          ➜ ~ ansible-playbook example.yml 
          [WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

          [WARNING]: No inventory was parsed, only implicit localhost is available

          [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


          PLAY [localhost] ***********************************************************************************************************************

          TASK [Gathering Facts] *****************************************************************************************************************
          ok: [localhost]

          TASK [Include dictionary data] *********************************************************************************************************
          ok: [localhost]

          TASK [Show info field from data.yml] ***************************************************************************************************
          ok: [localhost] => (item=item_2) =>
          "msg": "Id: 18.3 - info: test2"

          ok: [localhost] => (item=item_3) =>
          "msg": "Id: 18.3 - info: test3"

          ok: [localhost] => (item=item_1) =>
          "msg": "Id: 18.3 - info: test1"


          PLAY RECAP *****************************************************************************************************************************
          localhost : ok=3 changed=0 unreachable=0 failed=0





          share|improve this answer













          I have tested it and it works, I have removed extra newlines from input_vars.yaml



          ➜ ~ cat input_vars.yaml 
          input_data:
          item_1:
          name: "test1"
          version: "18.3"
          item_2:
          name: "test2"
          version: "18.3"
          item_3:
          name: "test3"
          version: "18.3"

          ➜ ~ cat example.yml
          ---
          - hosts: localhost
          tasks:
          - name: Include dictionary data
          include_vars:
          file: input_vars.yaml
          - name: Show info field from data.yml
          debug:
          msg: "Id: input_data[item]['version'] - info: input_data[item]['name'] "
          with_items: " input_data.keys() "


          Output



          ➜ ~ ansible-playbook example.yml 
          [WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

          [WARNING]: No inventory was parsed, only implicit localhost is available

          [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


          PLAY [localhost] ***********************************************************************************************************************

          TASK [Gathering Facts] *****************************************************************************************************************
          ok: [localhost]

          TASK [Include dictionary data] *********************************************************************************************************
          ok: [localhost]

          TASK [Show info field from data.yml] ***************************************************************************************************
          ok: [localhost] => (item=item_2) =>
          "msg": "Id: 18.3 - info: test2"

          ok: [localhost] => (item=item_3) =>
          "msg": "Id: 18.3 - info: test3"

          ok: [localhost] => (item=item_1) =>
          "msg": "Id: 18.3 - info: test1"


          PLAY RECAP *****************************************************************************************************************************
          localhost : ok=3 changed=0 unreachable=0 failed=0






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 0:22









          Hernan GarciaHernan Garcia

          565315




          565315












          • Thanks. You are right, it worked.

            – drifter
            Mar 8 at 0:26

















          • Thanks. You are right, it worked.

            – drifter
            Mar 8 at 0:26
















          Thanks. You are right, it worked.

          – drifter
          Mar 8 at 0:26





          Thanks. You are right, it worked.

          – drifter
          Mar 8 at 0:26



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054586%2fansible-loop-over-dictionaries%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229