Skip to main content

Simple module containing various types of resource to manage files.

Project description

inmanta-module-files

pypi version build status

This package is an adapter that is meant to be used with the inmanta orchestrator: https://docs.inmanta.com

Features

This module allows to manage files, on a unix host. It contains the following resources:

  1. files::Directory: to manage a directory, its existence, permissions and ownership.
  2. files::TextFile: to manage a simple text file, its existence, content, permissions and ownership. This should not be used for big files, as the content of the file is embedded in the resource itself.
  3. files::HostFile: to manage hosts file entries (i.e. /etc/hosts), but allowing the file to be managed by other tools. The resource makes sure to only modify the entries defined in its desired state and leave the rest untouched.
  4. files::JsonFile and files::SharedJsonFile: to manage json file entries. Similarly to files::HostFile, only change in the file what is present in the desired state. The file can then still be modified by other tools.
  5. files::SystemdUnitFile: an entity representing a unit file, which exposes it most useful properties directly in the model. After being exported, this resource becomes nothing more than a text file.
  6. files::Symlink: to manage a symlink, its existence and ownership.

It also exposes the files::jinja plugin, to render a jinja template at compile time while keeping any reference it embeds (e.g. a secret) unresolved. Such references are then resolved by the agent, on the host, when the resource is deployed.

Example

The following example makes sure that the directory /example/folder/a exists, and creates a text file in it.

import mitogen
import files

import std

host = std::Host(
    name="localhost",
    os=std::linux,
    via=mitogen::Local(),
)

dir = files::Directory(
    host=host,
    path="/example/folder/a",
    # The directory that is managed is /example/folder/a, but the resource
    # will also make sure that any of its parent directories exists as well
    create_parents=true,
)

file = files::TextFile(
    host=host,
    path=f"{dir.path}/file.txt",
    content="test",
    # No need to explicitly add the dependency to the parent, the
    # exporter takes care of adding it
    # requires=dir,
)

Jinja templates with references

The files::jinja plugin renders a template stored in the project's templates/ folder. Inputs that are references, such as secrets pulled from the environment, are not resolved at compile time: they are kept in the rendered content and resolved by the agent, on the host, when the resource is deployed.

Given the following template, stored in templates/app.conf.j2:

[database]
password = {{ "APP_PASSWORD" | std.create_environment_reference() }}

The following example renders it into a text file, while keeping the password as an environment reference resolved at deploy time:

import mitogen
import files

import std

host = std::Host(
    name="localhost",
    os=std::linux,
    via=mitogen::Local(),
)

file = files::TextFile(
    host=host,
    path="/example/folder/app.conf",
    # The template is rendered at compile time, but the password, which
    # is an environment reference, is left untouched.  It is resolved by
    # the agent, on the host, when the resource is deployed.
    content=files::jinja("template:///app.conf.j2"),
)

Find more examples in the ´tests` folder of this module!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inmanta_module_files-2.11.1.tar.gz (50.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

inmanta_module_files-2.11.1-py3-none-any.whl (47.9 kB view details)

Uploaded Python 3

File details

Details for the file inmanta_module_files-2.11.1.tar.gz.

File metadata

  • Download URL: inmanta_module_files-2.11.1.tar.gz
  • Upload date:
  • Size: 50.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for inmanta_module_files-2.11.1.tar.gz
Algorithm Hash digest
SHA256 71ed7a6dbc3470d6e7476d3355e69c175aad2f419f35e5ba5f13ed14434f90cc
MD5 9f54f3a4808450e51133879fa92564c7
BLAKE2b-256 d9cfb3c1cfb61cf6afba7f4b18894088ad36adb869c7e5e64f48a8f9bf9858d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for inmanta_module_files-2.11.1.tar.gz:

Publisher: continuous-delivery.yml on edvgui/inmanta-module-files

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file inmanta_module_files-2.11.1-py3-none-any.whl.

File metadata

File hashes

Hashes for inmanta_module_files-2.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c7435c35aa0efde8379a1726e269c84b96eaafb29e16e495c1bf61aafbec1c6d
MD5 0975455d127229c32daea7d6bfb149f5
BLAKE2b-256 0e26d732d37f90f2d42bd323cade178f32a1904c4b33a347f09f9ae6aa98517d

See more details on using hashes here.

Provenance

The following attestation bundles were made for inmanta_module_files-2.11.1-py3-none-any.whl:

Publisher: continuous-delivery.yml on edvgui/inmanta-module-files

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page