{"id":1799,"library":"ansible","title":"Ansible","description":"Ansible is a radically simple IT automation engine that automates cloud provisioning, configuration management, application deployment, intra-service orchestration, and other IT needs. The `ansible` PyPI package (currently v13.5.0) is a meta-package that bundles `ansible-core` (the engine) and various `ansible-collections` for modules and plugins. It follows a release cadence tied to the `ansible-core` and collection ecosystem, with major updates typically released quarterly.","status":"active","version":"13.5.0","language":"en","source_language":"en","source_url":"https://github.com/ansible/ansible","tags":["automation","configuration management","orchestration","devops","infrastructure as code"],"install":[{"cmd":"pip install ansible","lang":"bash","label":"Install the full Ansible meta-package"},{"cmd":"pip install ansible-core","lang":"bash","label":"Install only the core engine (lighter)"},{"cmd":"pip install ansible-runner","lang":"bash","label":"Install for programmatic execution (recommended)"}],"dependencies":[{"reason":"The underlying engine for Ansible operations, automatically installed by the `ansible` meta-package.","package":"ansible-core","optional":false},{"reason":"Recommended for stable programmatic execution of playbooks and ad-hoc commands in Python.","package":"ansible-runner","optional":true},{"reason":"Various collections providing modules, plugins, etc., automatically installed by the `ansible` meta-package.","package":"ansible-collections.*","optional":false}],"imports":[{"note":"Most programmatic interaction with Ansible should use `ansible-runner` for stability. Direct imports from `ansible.*` internal modules are generally discouraged as they are unstable internal APIs.","symbol":"run","correct":"from ansible_runner import run"}],"quickstart":{"code":"import os\nimport shutil\nimport ansible_runner\n\n# Define a simple playbook\nplaybook_content = \"\"\"\n- name: Hello Ansible\n  hosts: localhost\n  gather_facts: no\n  tasks:\n    - name: Display message\n      ansible.builtin.debug:\n        msg: \"Ansible is running from Python!\"\n\"\"\"\n\n# Create a temporary directory for the run\ntemp_dir = \"./ansible_quickstart_temp\"\nos.makedirs(temp_dir, exist_ok=True)\n\n# Write the playbook to a file in the temp directory\nplaybook_path = os.path.join(temp_dir, \"hello.yml\")\nwith open(playbook_path, \"w\") as f:\n    f.write(playbook_content)\n\ntry:\n    # Run the playbook using ansible-runner\n    # private_data_dir is essential for ansible-runner to function\n    r = ansible_runner.run(\n        private_data_dir=temp_dir,\n        playbook=\"hello.yml\",\n        inventory={\"localhost\": {\"hosts\": [\"localhost\"]}}, # Minimal inventory\n        quiet=True # Suppress some verbose output\n    )\n\n    print(f\"\\nAnsible Runner Status: {r.status}\")\n    if r.rc == 0:\n        print(\"Playbook executed successfully.\")\n        # Optionally, print captured stdout from events\n        for event in r.events:\n            if 'event' in event and event['event'] == 'runner_on_ok' and 'msg' in event['event_data']['res']:\n                print(f\"  Task output: {event['event_data']['res']['msg']}\")\n    else:\n        print(f\"Playbook failed with return code: {r.rc}\")\n        print(f\"Errors: {r.stderr}\") # ansible-runner captures stderr\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    # Clean up the temporary directory\n    if os.path.exists(temp_dir):\n        shutil.rmtree(temp_dir)\n    print(\"Cleanup complete.\")","lang":"python","description":"This quickstart demonstrates running a simple Ansible playbook programmatically using `ansible-runner`. It creates a temporary directory for Ansible to work in, defines a basic playbook, and executes it. Ensure `ansible-runner` is installed (`pip install ansible-runner`)."},"warnings":[{"fix":"Evaluate your specific needs. If you only need the core engine or programmatic execution via `ansible-runner`, install `ansible-core` or `ansible-runner` directly.","message":"The `ansible` PyPI package is a meta-package. It installs `ansible-core` and many `ansible-collections`. For minimal setups or specific programmatic tasks, `pip install ansible-core` or `pip install ansible-runner` might be sufficient and lead to a smaller installation footprint.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always check the `requires_python` metadata on PyPI for the specific `ansible` or `ansible-core` version you intend to use. Ensure your Python environment meets the requirements.","message":"Python version compatibility changes frequently with `ansible-core` releases. Newer `ansible-core` versions drop support for older Python versions. The `ansible` meta-package version 13.5.0 requires Python >=3.12, reflecting its underlying `ansible-core` 2.16.x.","severity":"breaking","affected_versions":"All major `ansible-core` upgrades (e.g., 2.12, 2.15, 2.16 and beyond)"},{"fix":"Use `ansible-runner` for stable and officially supported programmatic execution of Ansible playbooks and commands in Python. It provides a robust API that is less likely to break.","message":"Directly importing from `ansible.*` internal modules (e.g., `ansible.playbook`, `ansible.executor`) for programmatic interaction is generally discouraged. These are internal APIs and are subject to change without warning between versions, leading to unstable code.","severity":"gotcha","affected_versions":"All versions, especially across `ansible-core` major changes"},{"fix":"Refer to the `ansible-core` release notes (e.g., `https://docs.ansible.com/ansible/devel/dev_guide/developing_breaking_changes.html`) before upgrading. Thoroughly test custom code and playbooks with new versions.","message":"Major version upgrades of `ansible-core` (e.g., 2.9 to 2.10, 2.11 to 2.12, etc.) frequently introduce breaking changes in module arguments, plugin interfaces, and internal data structures. This can affect custom modules, plugins, or scripts that directly interact with Ansible's internals.","severity":"breaking","affected_versions":"All major `ansible-core` upgrades"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}