'dict object' has no attribute 'stdout' in Ansible Playbook

25,973

An inspection of - debug: var=vault_contents will show you that when used with a looping construct such as with_items:, the register variable has a list called results containing the outcomes for each iteration of the loop. This is also documented in the fine manual.

So, what you want is likely:

- debug:
    msg: "JBoss config {{ item.item }} does not contain the word vault"
  when: item.stdout.find('$VAULT') == -1
  with_items: '{{ vault_contents.results }}'
Share:
25,973
anish anil
Author by

anish anil

Updated on July 09, 2022

Comments

  • anish anil
    anish anil almost 2 years

    My playbook:

    - name: JBoss KeyStore and Truststore passwords will be stored in the          password vault
        #shell: less "{{ vault }}"
         shell: cat "{{ vault }}"
        register: vault_contents
        tags:
          - BW.6.1.1.10
        with_items:
          - "{{ vault }}"
      - debug:
           msg: "JBoss config filedoes not contains the word vault"
        when: vault_contents.stdout.find('$VAULT') == -1
    

    I'm trying to read multiple files through ansible using Jinga2 Template and parse the output as stdout and search for a keyword and report it.

    It fails with the below error:

    TASK [testing_roles : debug]   **************************************************************************.   *****************************************************************
    fatal: [d84e4fe137f4]: FAILED! => {"failed": true, "msg": "The conditional check 'vault_contents.stdout.find('$VAULT') == -1' failed. 
    The error was: error while evaluating conditional (vault_contents.stdout.find('$VAULT') == -1): 'dict object' has no attribute 'stdout'\n\nThe error appears to have been in '/Ansible/Ansible/Relearn/testing_roles/roles/testing_roles/tasks/main.yml': line 49, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n      - \"{{ vault }}\"\n  - debug:\n    ^ here\n"}
    to retry, use: --limit @/Ansible/Ansible/Relearn/testing_roles/playbook.retry
    

    When i append it with a single file entry it works as expected but when it is changes to a series of files it fails.

    Is this the right approach to scan multiple files in Ansible or should be be using some other module or method.

    Any help is greatly appreciated.

    In the vars file it has the below contents:

    vault:
      - /jboss-as-7.1.1.Final/standalone/configuration/standalone-full-ha.xml
    

    Thank you

  • anish anil
    anish anil over 5 years
    Thank you, N yes, I missed reading the documentation completely