ansible/docs/docsite/rst/dev_guide/developing_api.rst

48 lines
2.1 KiB
ReStructuredText
Raw Normal View History

.. _developing_api:
**********
2016-09-23 22:48:37 +02:00
Python API
**********
2016-09-23 22:48:37 +02:00
.. contents:: Topics
Docs [2.10] Backportapalooza 6 (#71129) * Misc typo fixes (#71089) (cherry picked from commit 504ef607f350f0411fede8576d8feb2b0195cc70) * Add some documentation for the format of meta/runtime.yml (#71035) * Document the format of meta/runtime.yml * Document multiple Ansible versions Clarify difference between deprecation and tombstone fields * add note (cherry picked from commit a9eb8b04882669bd17cd82780c908863e7504886) * add note to uninstall older versions of ansible for pip (#71023) * add note to uninstall older versions of ansible for pip * combine with the other PR (cherry picked from commit 72d3d441632d0e6ef6d2a057392f8165ffd8c65a) * VMware: Inventory scenario guide for hostnames (#71055) Added a scenario guide for ``hostnames`` parameter for vmware_vm_inventory. Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> (cherry picked from commit 0055673c704afd555053d6e2239ac2666ad60e56) * Document string tests a bit more (#71049) - Explain how `regex` differs from `match` and `search`. - Document `multiline` and `ignorecase`. Signed-off-by: Rick Elrod <rick@elrod.me> (cherry picked from commit 701c638757949280c875edc0eb364ee0e63db4bb) * docs: Add a note about package requirements for fact gathering (#70796) Fixes: #26148 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> (cherry picked from commit a6725d6e2af2f950979a0ed370aee786daabf926) * added note about fakeroot (#71018) see #70895 (cherry picked from commit 11a31e99e6b3395b624a7c74ea64b055434c9ea1) * Update documentation of httpapi's handle_httperror method for clarity (#70991) (cherry picked from commit a0523e5b8a7c183b59836ad891c2af8b6c091ebb) * DOCS: add 2.10 collections roadmap (#70975) * draft of 2.10 collections roadmap * incorporates feedback from felixfontein * gundalow and samccann feedback, fix link Co-authored-by: Alicia Cozine <acozine@users.noreply.github.com> (cherry picked from commit 9879da8e23b01405c20529d700cc38c7863853db) * updates changelog types; some updates for easier translation (#71027) Co-authored-by: Alicia Cozine <acozine@users.noreply.github.com> Co-authored-by: Felix Fontein <felix@fontein.de> (cherry picked from commit 4f4436c1240d38bd95829fd0fc31e456864dc24a) * Document common return values with examples (#71046) * adding return value examples * shift to console code blocks * cleaning up whitespace and shortening invocation example * reordering diff section (cherry picked from commit 864573a38d109fa5299b57ce2eefd0aa2bbfef5e) * Update intro_getting_started.rst (#71039) Added two additional learning resources in the See also: section- forgot closing backticks (cherry picked from commit 9850915bd61d7e25d02907ce2b990e73beb27854) * Guide users to use ansible-runner (#71063) Update the docs to guide users to use `ansible-runner` instead of using Python API directly. In many use cases, executing Ansible playbooks are sufficient. In those use cases, `ansible-runner` is easier and much stable to use comparing with Python API, but there is no mention of it. (cherry picked from commit 0c855dc70bde3b737329689823be03496026d976) * Porting guides for ansible-base 2.10 and ansible 2.10 (#70891) * Fix changelog link title. * Rename Ansible 2.10 and 2.11 porting guides to Ansible-base porting guides. * Add stub for automatically generated 2.10 porting guide. * Move things that should not be in the ansible-base porting guide to the ansible porting guide. * Apply changes to base porting guides. * Add remark that ansible-base is mainly for developers. * Ansible Base -> Ansible-base * Fix link in base porting guide. * Add generated porting guide. * Use same header signs as antsibull-changelog's RST builder. * Update generated porting guide. (cherry picked from commit 61b36c6f3087614cc7ed1a2cca590f74de8d7188) * Update network platform guides with FQCN (#70699) * fqcn all the docs things! (cherry picked from commit 54bee7152b70409f751aefb4affafdd3867df87b) * Document how to upgrade to ansible with pip (#70768) Fixes #70348 (cherry picked from commit 50193356605a9f96caf7772c331ff0950afa4c7c) * document how to migrate between collections (#70243) * document how to migrate between collections * Apply suggestions from code review Co-authored-by: John R Barker <john@johnrbarker.com> Co-authored-by: Felix Fontein <felix@fontein.de> (cherry picked from commit 58145dff9ca1a713f8ed295a0076779a91c41cba) * remove github link from plugins (#70951) (cherry picked from commit e28b20d72930ad8c0a359de05e05726090165fda) * Add latest rc from ansible-base (#70974) * Add latest rc from ansible-base (cherry picked from commit d62dffafb3671dfc331eef6a847dde05b24a73d0) * Document to_json will convert to ASCII strings by default (#70954) ... as reported in issue #68702 (cherry picked from commit 8c48366f1c2b184341ae1d0b9d62eb6bd0df506a) * Update the porting guide for ansible-2.10.0a8 (#71141) (cherry picked from commit 0a9638ce4bf7f1b4a87c68dc3ca8cd05249d79be) Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com> Co-authored-by: Sloane Hertel <shertel@redhat.com> Co-authored-by: Rick Elrod <rick@elrod.me> Co-authored-by: Brian Coca <bcoca@users.noreply.github.com> Co-authored-by: Nathaniel Case <ncase@redhat.com> Co-authored-by: Alicia Cozine <879121+acozine@users.noreply.github.com> Co-authored-by: Terciero <terciero@users.noreply.github.com> Co-authored-by: Brendon O'Sullivan <49501251+bjosullivan@users.noreply.github.com> Co-authored-by: EthanHur <ethan0311@gmail.com> Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Baptiste Mille-Mathias <baptiste.millemathias@gmail.com> Co-authored-by: Toshio Kuratomi <a.badger@gmail.com>
2020-08-07 23:04:19 +02:00
.. note:: This API is intended for internal Ansible use. Ansible may make changes to this API at any time that could break backward compatibility with older versions of the API. Because of this, external use is not supported by Ansible. If you want to use Python API only for executing playbooks or modules, consider `ansible-runner <https://ansible-runner.readthedocs.io/en/latest/>`_ first.
2016-09-23 22:48:37 +02:00
2018-03-02 23:51:48 +01:00
There are several ways to use Ansible from an API perspective. You can use
the Ansible Python API to control nodes, you can extend Ansible to respond to various Python events, you can
write plugins, and you can plug in inventory data from external data sources. This document
gives a basic overview and examples of the Ansible execution and playbook API.
2016-09-23 22:48:37 +02:00
If you would like to use Ansible programmatically from a language other than Python, trigger events asynchronously,
or have access control and logging demands, please see the `Ansible Tower documentation <https://docs.ansible.com/ansible-tower/>`_.
2016-09-23 22:48:37 +02:00
2018-03-02 23:51:48 +01:00
.. note:: Because Ansible relies on forking processes, this API is not thread safe.
2016-09-23 22:48:37 +02:00
.. _python_api_example:
2016-09-23 22:48:37 +02:00
Python API example
==================
2016-09-23 22:48:37 +02:00
This example is a simple demonstration that shows how to minimally run a couple of tasks:
2016-09-23 22:48:37 +02:00
.. literalinclude:: ../../../../examples/scripts/uptime.py
:language: python
2016-09-23 22:48:37 +02:00
.. note:: Ansible emits warnings and errors via the display object, which prints directly to stdout, stderr and the Ansible log.
2016-09-23 22:48:37 +02:00
2018-03-02 23:51:48 +01:00
The source code for the ``ansible``
command line tools (``lib/ansible/cli/``) is `available on GitHub <https://github.com/ansible/ansible/tree/devel/lib/ansible/cli>`_.
2016-09-23 22:48:37 +02:00
.. seealso::
:ref:`developing_inventory`
2016-09-23 22:48:37 +02:00
Developing dynamic inventory integrations
:ref:`developing_modules_general`
Getting started on developing a module
:ref:`developing_plugins`
2016-09-23 22:48:37 +02:00
How to develop plugins
`Development Mailing List <https://groups.google.com/group/ansible-devel>`_
2016-09-23 22:48:37 +02:00
Mailing list for development topics
`irc.freenode.net <http://irc.freenode.net>`_
#ansible IRC chat channel