.. _quickstart: Quickstart ========== Once you have pypuppetdb installed you can configure it to connect to PuppetDB and take it from there. Connecting ---------- The first thing you need to do is to connect with PuppetDB: .. code-block:: python >>> from pypuppetdb import connect >>> db = connect() Nodes ----- The following will return a generator object yielding Node objects for every returned node from PuppetDB. .. code-block:: python >>> nodes = db.nodes() >>> for node in nodes: >>> print(node) host1 host2 ... To query a single node the singular `node()` can be used: .. code-block:: python >>> node = db.node('hostname') >>> print(node) hostname Node scope ~~~~~~~~~~ The Node objects are a bit more special in that they can query for facts and resources themselves. Using those methods from a node object will automatically add a query to the request scoping the request to the node. .. code-block:: python >>> node = db.node('hostname') >>> print(node.fact('osfamily')) osfamily/hostname Facts ----- .. code-block:: python >>> facts = db.facts('osfamily') >>> for fact in facts: >>> print(fact) osfamily/host1 osfamily/host2 That queries PuppetDB for the 'osfamily' fact and will yield Fact objects, one per node this fact is known for. Resources --------- .. code-block:: python >>> resources = db.resources('file') Will return a generator object containing all file resources you're managing across your infrastructure. This is probably a bad idea if you have a big number of nodes as the response will be huge.