{"id":23375820,"url":"https://github.com/diefans/ansible-sucks-module","last_synced_at":"2025-04-10T18:16:15.194Z","repository":{"id":150729158,"uuid":"304656201","full_name":"diefans/ansible-sucks-module","owner":"diefans","description":"Anti-sucking ansible module","archived":false,"fork":false,"pushed_at":"2020-10-18T16:00:27.000Z","size":3,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T15:52:36.462Z","etag":null,"topics":["ansible","sucks"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/diefans.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-16T14:47:55.000Z","updated_at":"2022-11-22T13:24:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"a8f14e1a-d3a9-4d0b-9edb-241ed35901d3","html_url":"https://github.com/diefans/ansible-sucks-module","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diefans%2Fansible-sucks-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diefans%2Fansible-sucks-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diefans%2Fansible-sucks-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diefans%2Fansible-sucks-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/diefans","download_url":"https://codeload.github.com/diefans/ansible-sucks-module/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248269725,"owners_count":21075785,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","sucks"],"created_at":"2024-12-21T17:18:43.276Z","updated_at":"2025-04-10T18:16:15.189Z","avatar_url":"https://github.com/diefans.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ansible-sucks-module\n\nThis ansible module serves as an anti-sucking tool to help developers maintain their mental integrity when forced to work with ansible.\n\n\n# Features\n\nEnables the developer to avoid the most crazy driving ansible feature: using jinja2 substitution to construct meaningful data structures from facts and back to facts.\n\n\n# Background\n\nAnsible seemes nice, but only for simple stuff like provisioning. When you have to maintain complex setups, you inevitably have to deal with ansible facts, the inventory and transformation of those into tool specific configurations and data structures.\n\nFinally you force yourself registering a lot of _intermediate_ variables, [looping](https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html) over those and using a lot of [jinja filters](https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html). Your transformation becomes a distributed incomprehensible nightmare.\n\nIf you return a little later and try to make a sense out of it, you find yourself cursing and your head gets smashed by the pure insanity under which you subjugated yourself. Ansible is a monster eating the soul of every brave developer - if you ever had a chance to review the ansible code, you know you are fighting the devil \u003csup\u003e[1](#pathtohell)\u003c/sup\u003e.\n\n\n# Internals\n\nBasically this module executes a python code block via `exec`. You can provide `locals` to it. If you want to register the result, use `set_result(**kwargs)` if you want to create some facts use `set_facts(**kwargs)`\n\n```python\ndef run_module():\n    module_args = {\n        \"code\": {\"type\": \"str\", \"required\": True},\n        \"locals\": {\"type\": \"dict\", \"required\": False, \"default\": {}},\n    }\n    module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)\n\n    result = {}\n    facts = {}\n    _globals = {\n        \"set_result\": result.update,\n        \"set_facts\": facts.update,\n        # copy locals, since ansible tries to clean it up afterwards, but fails\n        # for e.g. imported modules\n        **module.params[\"locals\"],\n    }\n    code_object = compile(module.params[\"code\"], \"\u003cstring\u003e\", \"exec\")\n    # imported names settle in locals, so we unite locals and globals, to have\n    # them available\n    exec(code_object, _globals, _globals)\n\n    result[\"ansible_facts\"] = facts\n    module.exit_json(msg=\"Code executed\", **result)\n```\n\n# Usage\n\nClone the project and add the project path to `ANSIBLE_LIBRARY` or define `library` accordingly in `ansible.cfg` (see [docs](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-module-path)).\n\n```yaml\n- name: Get database IPs\n  run_once: yes\n  delegate_to: localhost\n  py:\n    locals:\n      names: \"{{ groups['database'] }}\"\n    code: |\n      import socket\n      ips = [socket.gethostbyname(name) for name in names]\n      set_facts(database_ips=ips)\n\n- debug:\n    var: database_ips\n```\n\n\u003csub\u003e\u003ca name=\"pathtohell\"\u003e1\u003c/a\u003e: Der Pfad zur Hölle ist gepflastert mit guten Absichten.\u003c/sub\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiefans%2Fansible-sucks-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiefans%2Fansible-sucks-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiefans%2Fansible-sucks-module/lists"}