ansible / ansible

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy and maintain. Automate everything from code deployment to network configuration to cloud management, in a language that approaches plain English, using SSH, with no agents to install on remote systems. https://docs.ansible.com.
https://www.ansible.com/
GNU General Public License v3.0
62.95k stars 23.91k forks source link

dict object' has no attribute 'json'"} #54561

Closed flaviomeyer closed 5 years ago

flaviomeyer commented 5 years ago
SUMMARY
ISSUE TYPE
COMPONENT NAME

uri

ANSIBLE VERSION
ansible 2.7.8
  config file = None
  configured module search path = ['/Users/fmeyer/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.7.8/libexec/lib/python3.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.7.2 (default, Feb 12 2019, 08:15:36) [Clang 10.0.0 (clang-1000.11.45.5)]
CONFIGURATION
OS / ENVIRONMENT

Target OS: CentOS 7.6

STEPS TO REPRODUCE
**Playbook:**
- name: check if AEM Publish successfully installed
  uri:
    url: http://localhost:4503/system/console/bundles.json
    method: GET
    return_content: yes
    status_code: 200
    body_format: json
    user: admin
    password: admin
  register: result
  until: "result.json.s[4] == 0"
  retries: 30
  delay: 30

**Error:**
TASK [test : check if AEM Publish successfully installed] *******************************************
fatal: [192.168.25.142]: FAILED! => {"msg": "The conditional check 'result.json.s[4] == 0' failed. The error was: error while evaluating conditional (result.json.s[4] == 0): 'dict object' has no attribute 'json'"}
EXPECTED RESULTS

Write value 0 to variable result when output of json parsing is value 0

ACTUAL RESULTS

ansible-playbook -i /Users/fmeyer/.ansible/hosts playbook/aem_test.yml -vvv ansible-playbook 2.7.8 config file = None configured module search path = ['/Users/fmeyer/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/Cellar/ansible/2.7.8/libexec/lib/python3.7/site-packages/ansible executable location = /usr/local/bin/ansible-playbook python version = 3.7.2 (default, Feb 12 2019, 08:15:36) [Clang 10.0.0 (clang-1000.11.45.5)] No config file found; using defaults /Users/fmeyer/.ansible/hosts did not meet host_list requirements, check plugin documentation if this is unexpected /Users/fmeyer/.ansible/hosts did not meet script requirements, check plugin documentation if this is unexpected Parsed /Users/fmeyer/.ansible/hosts inventory source with ini plugin

PLAYBOOK: aem_test.yml ** 1 plays in playbook/aem_test.yml

PLAY [aem_test] ***** META: ran handlers

TASK [test : check if AEM Publish successfully installed] *** task path: /Users/fmeyer/git/ansible/test/tasks/main.yml:2 <192.168.25.142> ESTABLISH SSH CONNECTION FOR USER: root <192.168.25.142> SSH: EXEC sshpass -d41 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/Users/fmeyer/.ansible/cp/3bcfb0a675 192.168.25.142 '/bin/sh -c '"'"'echo ~root && sleep 0'"'"'' <192.168.25.142> (0, b'/root\n', b'') <192.168.25.142> ESTABLISH SSH CONNECTION FOR USER: root <192.168.25.142> SSH: EXEC sshpass -d41 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/Users/fmeyer/.ansible/cp/3bcfb0a675 192.168.25.142 '/bin/sh -c '"'"'( umask 77 && mkdir -p "echo /root/.ansible/tmp/ansible-tmp-1553806800.1948202-246961565380639" && echo ansible-tmp-1553806800.1948202-246961565380639="echo /root/.ansible/tmp/ansible-tmp-1553806800.1948202-246961565380639" ) && sleep 0'"'"'' <192.168.25.142> (0, b'ansible-tmp-1553806800.1948202-246961565380639=/root/.ansible/tmp/ansible-tmp-1553806800.1948202-246961565380639\n', b'') Using module file /usr/local/Cellar/ansible/2.7.8/libexec/lib/python3.7/site-packages/ansible/modules/net_tools/basics/uri.py <192.168.25.142> PUT /Users/fmeyer/.ansible/tmp/ansible-local-11900zwc6atju/tmpwa7hl9v3 TO /root/.ansible/tmp/ansible-tmp-1553806800.1948202-246961565380639/AnsiballZ_uri.py <192.168.25.142> SSH: EXEC sshpass -d41 sftp -o BatchMode=no -b - -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/Users/fmeyer/.ansible/cp/3bcfb0a675 '[192.168.25.142]' <192.168.25.142> (0, b'sftp> put /Users/fmeyer/.ansible/tmp/ansible-local-11900zwc6atju/tmpwa7hl9v3 /root/.ansible/tmp/ansible-tmp-1553806800.1948202-246961565380639/AnsiballZ_uri.py\n', b'') <192.168.25.142> ESTABLISH SSH CONNECTION FOR USER: root <192.168.25.142> SSH: EXEC sshpass -d41 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/Users/fmeyer/.ansible/cp/3bcfb0a675 192.168.25.142 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1553806800.1948202-246961565380639/ /root/.ansible/tmp/ansible-tmp-1553806800.1948202-246961565380639/AnsiballZ_uri.py && sleep 0'"'"'' <192.168.25.142> (0, b'', b'') <192.168.25.142> ESTABLISH SSH CONNECTION FOR USER: root <192.168.25.142> SSH: EXEC sshpass -d41 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/Users/fmeyer/.ansible/cp/3bcfb0a675 -tt 192.168.25.142 '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1553806800.1948202-246961565380639/AnsiballZ_uri.py && sleep 0'"'"'' <192.168.25.142> (1, b'\r\n{"status": 500, "content_length": "3247", "url": "http://localhost:4503/system/console/bundles.json", "content": "\n\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\nError 500 Server Error\n\n

HTTP ERROR 500

\n

Problem accessing /system/console/bundles.json. Reason:\n

    Server Error

Caused by:

org.apache.sling.api.auth.NoAuthenticationHandlerException\n\tat org.apache.sling.auth.core.impl.SlingAuthenticator.login(SlingAuthenticator.java:588)\n\tat org.apache.sling.extensions.webconsolesecurityprovider.internal.SlingWebConsoleSecurityProvider2.authenticate(SlingWebConsoleSecurityProvider2.java:91)\n\tat org.apache.felix.webconsole.internal.servlet.OsgiManagerHttpContext.handleSecurity(OsgiManagerHttpContext.java:103)\n\tat org.apache.felix.http.base.internal.service.ServletContextImpl.handleSecurity(ServletContextImpl.java:406)\n\tat org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:58)\n\tat org.apache.felix.http.base.internal.dispatch.Dispatcher$1.doFilter(Dispatcher.java:146)\n\tat org.apache.felix.http.base.internal.whiteboard.WhiteboardManager.invokePreprocessors(WhiteboardManager.java:1000)\n\tat org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:91)\n\tat org.apache.felix.http.base.internal.dispatch.DispatcherServlet.service(DispatcherServlet.java:49)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:725)\n\tat org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:865)\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:535)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)\n\tat org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1340)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1242)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)\n\tat org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:220)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)\n\tat org.eclipse.jetty.server.Server.handle(Server.java:503)\n\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364)\n\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)\n\tat org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)\n\tat org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)\n\tat org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)\n\tat java.lang.Thread.run(Thread.java:748)\n
\n\n\n\n", "failed": true, "connection": "close", "content_type": "text/html;charset=iso-8859-1", "invocation": {"module_args": {"directory_mode": null, "force": false, "remote_src": null, "status_code": ["200"], "body_format": "json", "owner": null, "follow": false, "client_key": null, "group": null, "use_proxy": true, "unsafe_writes": null, "setype": null, "content": null, "serole": null, "follow_redirects": "safe", "return_content": true, "method": "GET", "body": null, "url_username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "url_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "dest": null, "selevel": null, "force_basic_auth": false, "removes": null, "http_agent": "ansible-httpget", "user": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "regexp": null, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "src": null, "url": "http://localhost:4503/system/console/bundles.json", "validate_certs": true, "seuser": null, "client_cert": null, "creates": null, "headers": {"Content-Type": "application/json"}, "delimiter": null, "mode": null, "timeout": 30, "attributes": null, "backup": null}}, "date": "Thu, 28 Mar 2019 18:03:22 GMT", "redirected": false, "cache_control": "must-revalidate,no-cache,no-store", "msg": "Status code was 500 and not [200]: HTTP Error 500: Server Error"}\r\n', b'Shared connection to 192.168.25.142 closed.\r\n') <192.168.25.142> Failed to connect to the host via ssh: Shared connection to 192.168.25.142 closed. <192.168.25.142> ESTABLISH SSH CONNECTION FOR USER: root <192.168.25.142> SSH: EXEC sshpass -d41 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/Users/fmeyer/.ansible/cp/3bcfb0a675 192.168.25.142 '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1553806800.1948202-246961565380639/ > /dev/null 2>&1 && sleep 0'"'"'' <192.168.25.142> (0, b'', b'') fatal: [192.168.25.142]: FAILED! => { "msg": "The conditional check 'result.json.s[4] == 0' failed. The error was: error while evaluating conditional (result.json.s[4] == 0): 'dict object' has no attribute 'json'" }

sivel commented 5 years ago

As you are doing an until loop, and checking for a specific attribute, you will need to make sure that even when the request fails, and that attribute is not available that the until doesn't fail as such.

Something like:

until: (result.json|default(dict(s=[1,1,1,1,1]))).s[4] == 0"

If you have further questions please stop by IRC or the mailing list:

flaviomeyer commented 5 years ago

@sivel Thanks it works with "until: (result.json|default(dict(s=[1,1,1,1,1]))).s[4] == 0".

DevakrishnanNampoothiri commented 5 years ago

Hi @meyerf99 and @sivel

I'am facing the issue @meyerf99 mentioned below. it's verify helpful for me if you can able to help in this case.

Error -:

2019-05-27 20:45:16,635 INFO: TASK [include_tasks] *** task path: /usr/share/opnfv-apex/ansible/playbooks/prepare_overcloud_containers.yml:31 fatal: [192.168.122.244]: FAILED! => {"msg": "The conditional check 'item in (response.json)['repositories']|join(\" \")' failed. The error was: error while evaluating conditional (item in (response.json)['repositories']|join(\" \")): 'dict object' has no attribute 'json'

The error appears to be in '/usr/share/opnfv-apex/ansible/playbooks/prepare_overcloud_containers.yml': line 31, column 7, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  register: response
- include_tasks: patch_containers.yml
  ^ here

"}

2019-05-27 20:45:16,635 INFO: PLAY RECAP ***** 192.168.122.244 : ok=5 changed=3 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

============================================================================== ### Below is the line were error showing in playbook.

     _register: response
    - include_tasks: patch_containers.yml
      with_items: "{{ patched_docker_services }}"
      loop_control:
        loop_var: item
      when:
        - patched_docker_services|length > 0
        - item in (response.json)['repositories']|join(" ")