{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/1298","labels_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/1298/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/1298/comments","events_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/1298/events","html_url":"https://github.com/ansible/ansible-modules-extras/pull/1298","id":119361904,"number":1298,"title":"safe json importing","user":{"login":"tronicum","id":534773,"avatar_url":"https://avatars.githubusercontent.com/u/534773?v=3","gravatar_id":"","url":"https://api.github.com/users/tronicum","html_url":"https://github.com/tronicum","followers_url":"https://api.github.com/users/tronicum/followers","following_url":"https://api.github.com/users/tronicum/following{/other_user}","gists_url":"https://api.github.com/users/tronicum/gists{/gist_id}","starred_url":"https://api.github.com/users/tronicum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tronicum/subscriptions","organizations_url":"https://api.github.com/users/tronicum/orgs","repos_url":"https://api.github.com/users/tronicum/repos","events_url":"https://api.github.com/users/tronicum/events{/privacy}","received_events_url":"https://api.github.com/users/tronicum/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ansible/ansible-modules-extras/labels/core_review","name":"core_review","color":"fad8c7"},{"url":"https://api.github.com/repos/ansible/ansible-modules-extras/labels/needs_info","name":"needs_info","color":"eb6420"},{"url":"https://api.github.com/repos/ansible/ansible-modules-extras/labels/needs_revision","name":"needs_revision","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2015-11-29T14:12:38Z","updated_at":"2016-01-11T20:29:19Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ansible/ansible-modules-extras/pulls/1298","html_url":"https://github.com/ansible/ansible-modules-extras/pull/1298","diff_url":"https://github.com/ansible/ansible-modules-extras/pull/1298.diff","patch_url":"https://github.com/ansible/ansible-modules-extras/pull/1298.patch"},"body":"exchanged all json imports with a fail safe variant for simplejson\r\nSee also pull request #1284.\r\nimport code is taken from module_utils/basic.py\r\nredundancy is wanted as stated in above pull request notes."},"comment":{"url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/comments/170680525","html_url":"https://github.com/ansible/ansible-modules-extras/pull/1298#issuecomment-170680525","issue_url":"https://api.github.com/repos/ansible/ansible-modules-extras/issues/1298","id":170680525,"user":{"login":"abadger","id":209242,"avatar_url":"https://avatars.githubusercontent.com/u/209242?v=3","gravatar_id":"","url":"https://api.github.com/users/abadger","html_url":"https://github.com/abadger","followers_url":"https://api.github.com/users/abadger/followers","following_url":"https://api.github.com/users/abadger/following{/other_user}","gists_url":"https://api.github.com/users/abadger/gists{/gist_id}","starred_url":"https://api.github.com/users/abadger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abadger/subscriptions","organizations_url":"https://api.github.com/users/abadger/orgs","repos_url":"https://api.github.com/users/abadger/repos","events_url":"https://api.github.com/users/abadger/events{/privacy}","received_events_url":"https://api.github.com/users/abadger/received_events","type":"User","site_admin":false},"created_at":"2016-01-11T20:29:19Z","updated_at":"2016-01-11T20:29:19Z","body":"I'm hoping that ziploader will hit in 2.1.0.  However, 2.0 is what we're working on releasing in January so it will be about 4 months before it is in an ansible release.\r\n\r\nLooking at your use case, I don't think we need most of this boilerplate.  In the module code we should be able to just get away with this:\r\n\r\n``` python\r\ntry:\r\n     import json\r\nexcept ImportError:\r\n    try:\r\n        import simplejson as json\r\n    except:\r\n        # Let snippet from module_utils/basic.py return a proper error in this case\r\n        pass\r\n```\r\n\r\nThe other portions of the module_utils code deal with two corner cases:\r\n\r\n1. A different module with an incompatible API occupies the json namespace. Importing json here shouldn't interfere with the module_utils snippet doing that check later so we don't need to repeat it here.\r\n2. Neither simplejson nor json are present on the system and we want to return a proper ansible error for that.  We have to prevent a traceback in this case but.  We don't have to return the error here, though, as the module_utils snippet will also do that check later and return the error properly.\r\n\r\nI think the recipe I give above is simple enough that we can put that in the modules instead of copying the entirety of what module_utils does.\r\n\r\nFor use on CentOS5 we also shouldn't need to modify all of these modules.  Only the modules that actually can run with python-2.4 need to be changed.  Some of the modules are also importing json but not using the json library at all.  For those, it's best to remove the \"import json\" altogether.\r\n\r\nNo need to change:\r\n* sns_topic.py  [requires boto which requires python-2.6+]\r\n* docker_login.py [requires docker-py which requires python-2.6+]\r\n* rabbitmq_binding.py [requires requests which requires python-2.6+]\r\n* rabbitmq_exchange.py [requires requests which requires python-2.6+]\r\n* rabbitmq_policy.py [requires requests which requires python-2.6+]\r\n* rabbitmq_queue.py [requires requests which requires python-2.6+]\r\n* circonus_annotation.py [ requires requests which requires python-2.6+]\r\n* typetalk [ has a proper fallback to simplejson with error handling]\r\n\r\nSafe to remove:\r\n* ecs_task.py\r\n* ecs_taskdefinition.py\r\n* route53_facts.py\r\n* vca_nat.py\r\n* consul.py\r\n* consul_kv.py\r\n* pacman.py\r\n* pkgin.py\r\n* pkgng.py\r\n* portinstall.py\r\n* urpmi.py\r\n\r\nNeeds modification:\r\n* riak.py [falls back to simplejson but will traceback if neither is installed]\r\n* boundary_meter.py\r\n* sensu_check.py [falls back to simplejson but will traceback if neither is installed]\r\n* stackdriver.py [falls back to simplejson but will traceback if neither is installed]\r\n* uptimerobot.py]\r\n* ipify_facts.py [falls back to simplejson but will traceback if neither is installed]\r\n* composer.py  [falls back to simplejson but will traceback if neither is installed]\r\n* npm.py [falls back to simplejson but will traceback if neither is installed]\r\n* github_hooks.py [falls back to simplejson but will traceback if neither is installed]\r\n* jira.py\r\n\r\n\r\nI'd be uncomfortable pushing this to 2.0.0 as we're planning on releasing that tomorrow but I can see it going into 2.0.1.  I'll work up a fix."}}