builtin operations¶
- class reemote.operations.builtin.script.Script(cmd: str = None, chdir: str = None, creates: str = None, decrypt: bool = True, executable: str = None, free_form: str = None, removes: str = None, guard: bool = True, sudo: bool = False, su: bool = False)[source]¶
Bases:
objectA class to encapsulate the functionality of running local scripts on remote nodes. The script is transferred to the remote node and then executed through the shell environment.
This module does not require Python on the remote system, similar to the raw module. It supports both Unix-like and Windows targets.
- cmd¶
Path to the local script followed by optional arguments.
- Type:
str
- chdir¶
Change into this directory on the remote node before running the script.
- Type:
str
- creates¶
A filename on the remote node; if it exists, the step will not run.
- Type:
str
- decrypt¶
Controls auto-decryption of source files using vault.
- Type:
bool
- executable¶
Name or path of an executable to invoke the script with.
- Type:
str
- free_form¶
Alternative way to specify the script path and arguments.
- Type:
str
- removes¶
A filename on the remote node; if it doesn’t exist, the step will not run.
- Type:
str
- guard¶
If False, the commands will not be executed.
- Type:
bool
- sudo¶
If True, the commands will be executed with sudo privileges.
- Type:
bool
- su¶
If True, the commands will be executed with su privileges.
- Type:
bool
Examples:
# Run a script with arguments (free form) r = yield Script("/some/local/script.sh --some-argument 1234") # Run a script with arguments (using explicit cmd parameter) r = yield Script(cmd="/some/local/script.sh --some-argument 1234") # Run a script only if file.txt does not exist on the remote node r = yield Script("/some/local/create_file.sh --some-argument 1234", creates="/the/created/file.txt") # Run a script only if file.txt exists on the remote node r = yield Script("/some/local/remove_file.sh --some-argument 1234", removes="/the/removed/file.txt") # Run a script using an executable in a non-system path r = yield Script("/some/local/script", executable="/some/remote/executable") # Run a script using an executable in a system path r = yield Script("/some/local/script.py", executable="python3")
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
It is usually preferable to write Ansible modules rather than pushing scripts.
If the path to the local script contains spaces, it needs to be quoted.
If the script returns non-UTF-8 data, it should be encoded (e.g., piped through base64).
For Windows targets, PowerShell scripts are supported.
Commands are constructed based on the sudo, and su flags.
- class reemote.operations.builtin.cron.Cron(name: str, user: str = None, minute: str = '*', hour: str = '*', day: str = '*', month: str = '*', weekday: str = '*', job: str = None, special_time: str = None, disabled: bool = False, env: bool = False, state: str = 'present', backup: bool = False, cron_file: str = None, insertafter: str = None, insertbefore: str = None)[source]¶
Bases:
objectA class to manage cron.d and crontab entries in Unix-like operating systems. This class allows you to create environment variables and named crontab entries, update, or delete them.
When crontab jobs are managed: the module includes one line with the description of the crontab entry “#Ansible: <name>” corresponding to the name passed to the module, which is used by future ansible/module calls to find/check the state. The name parameter should be unique, and changing the name value will result in a new cron task being created (or a different one being removed).
When environment variables are managed, no comment line is added, but, when the module needs to find/check the state, it uses the name parameter to find the environment variable definition line.
When using symbols such as %, they must be properly escaped.
- name¶
Description of a crontab entry or, if env is set, the name of environment variable.
- Type:
str
- user¶
The specific user whose crontab should be modified.
- Type:
str
- job¶
The command to execute or, if env is set, the value of environment variable.
- Type:
str
- special_time¶
Special time specification nickname.
- Type:
str
- disabled¶
If the job should be disabled (commented out) in the crontab.
- Type:
bool
- env¶
If set, manages a crontab’s environment variable.
- Type:
bool
- state¶
Whether to ensure the job or environment variable is present or absent.
- Type:
str
- backup¶
If set, create a backup of the crontab before it is modified.
- Type:
bool
- cron_file¶
If specified, uses this file instead of an individual user’s crontab.
- Type:
str
- insertafter¶
Used with state=present and env. Insert after specified environment variable.
- Type:
str
- insertbefore¶
Used with state=present and env. Insert before specified environment variable.
- Type:
str
Examples:
# Ensure a job that runs at 2 and 5 exists r = yield Cron( name="check dirs", minute="0", hour="5,2", job="ls -alh > /dev/null" ) # Ensure an old job is no longer present r = yield Cron( name="an old job", state="absent" ) # Creates an entry like "@reboot /some/job.sh" r = yield Cron( name="a job for reboot", special_time="reboot", job="/some/job.sh" ) # Creates an entry like "PATH=/opt/bin" on top of crontab r = yield Cron( name="PATH", env=True, job="/opt/bin" )
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
If you are experiencing permissions issues with cron and MacOS, you should see the official MacOS documentation for further information.
Requires cron (any ‘vixie cron’ conformant variant, like cronie)
- class reemote.operations.builtin.replace.Replace(path: str, regexp: str, replace: str = '', after: str = None, before: str = None, backup: bool = False, encoding: str = 'utf-8', group: str = None, mode: str = None, owner: str = None, selevel: str = None, serole: str = None, setype: str = None, seuser: str = None, unsafe_writes: bool = False, validate: str = None, attributes: str = None, guard: bool = True)[source]¶
Bases:
objectA class to encapsulate the functionality of the ansible.builtin.replace module. This module replaces all instances of a pattern within a file using regular expressions.
- path¶
The file to modify.
- Type:
str
- regexp¶
The regular expression to look for in the contents of the file.
- Type:
str
- replace¶
The string to replace regexp matches. Default: “”
- Type:
str
- after¶
If specified, only content after this match will be replaced/removed.
- Type:
str
- before¶
If specified, only content before this match will be replaced/removed.
- Type:
str
- backup¶
Create a backup file including the timestamp information.
- Type:
bool
- encoding¶
The character encoding for reading and writing the file. Default: “utf-8”
- Type:
str
- group¶
Name of the group that should own the filesystem object.
- Type:
str
- mode¶
The permissions the resulting filesystem object should have.
- Type:
str
- owner¶
Name of the user that should own the filesystem object.
- Type:
str
- selevel¶
The level part of the SELinux filesystem object context.
- Type:
str
- serole¶
The role part of the SELinux filesystem object context.
- Type:
str
- setype¶
The type part of the SELinux filesystem object context.
- Type:
str
- seuser¶
The user part of the SELinux filesystem object context.
- Type:
str
- unsafe_writes¶
Influence when to use atomic operation.
- Type:
bool
- validate¶
The validation command to run before copying the updated file.
- Type:
str
- attributes¶
The attributes the resulting filesystem object should have.
- Type:
str
- guard¶
If False the commands will not be executed.
- Type:
bool
Examples:
# Replace old hostname with new hostname r = yield Replace( path="/etc/hosts", regexp=r'(\s+)old\.host\.name(\s+.*)?$', replace='\1new.host.name\2' ) # Replace between expressions r = yield Replace( path="/etc/hosts", after=r'(?m)^<VirtualHost [*]>', before='</VirtualHost>', regexp=r'^(.+)$', replace='# \1' ) # Replace with file attributes r = yield Replace( path="/home/jdoe/.ssh/known_hosts", regexp=r'^old\.host\.name[^\n]*\n', owner="jdoe", group="jdoe", mode='0644' )
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
As of Ansible 2.3, the dest option has been changed to path as default.
As of Ansible 2.7.10, the combined use of before and after works properly.
Uses Python regular expressions with MULTILINE mode enabled.
- class reemote.operations.builtin.uri.Uri(url: str, method: str = 'GET', body=None, body_format: str = 'raw', headers: dict = None, url_username: str = None, url_password: str = None, validate_certs: bool = True, ca_path: str = None, client_cert: str = None, client_key: str = None, timeout: int = 30, follow_redirects: str = 'safe', force_basic_auth: bool = False, creates: str = None, removes: str = None, dest: str = None, return_content: bool = False, status_code: list = None)[source]¶
Bases:
objectA class to implement the Ansible uri module functionality using curl via shell commands. This class translates Ansible uri parameters into equivalent curl options.
- url¶
The HTTP or HTTPS URL to request.
- Type:
str
- method¶
The HTTP method (e.g., GET, POST, PUT, DELETE).
- Type:
str
- body¶
The body of the HTTP request/response.
- Type:
any
- body_format¶
The serialization format of the body (e.g., json, form-urlencoded).
- Type:
str
- headers¶
Custom HTTP headers.
- Type:
dict
- url_username¶
Username for authentication.
- Type:
str
- url_password¶
Password for authentication.
- Type:
str
- validate_certs¶
Whether to validate SSL certificates.
- Type:
bool
- ca_path¶
Path to a CA certificate bundle.
- Type:
str
- client_cert¶
Path to a client certificate file.
- Type:
str
- client_key¶
Path to a client private key file.
- Type:
str
- timeout¶
Socket-level timeout in seconds.
- Type:
int
- follow_redirects¶
Redirect behavior (e.g., all, none, safe).
- Type:
str
- force_basic_auth¶
Force Basic authentication on the initial request.
- Type:
bool
- creates¶
A filename; if it exists, the step will not run.
- Type:
str
- removes¶
A filename; if it does not exist, the step will not run.
- Type:
str
- dest¶
Path to download the response body.
- Type:
str
- return_content¶
Whether to return the response body as content.
- Type:
bool
- status_code¶
List of valid HTTP status codes for success.
- Type:
list
Examples:
# Example 1: Check that you can connect (GET) to a page and it returns a status 200 yield Uri( url="http://www.example.com", method="GET" ) # Example 2: Check that a page returns successfully but fail if the word "AWESOME" is not in the page contents yield Uri( url="http://www.example.com", method="GET", return_content=True ) # Example 3: Create a JIRA issue yield Uri( url="https://your.jira.example.com/rest/api/2/issue/", method="POST", body={"key": "value"}, # Replace with actual JSON payload body_format="json", url_username="your_username", url_password="your_pass", force_basic_auth=True, status_code=[201] ) # Example 4: Login to a form-based webpage and use the returned cookie to access the app in later tasks yield Uri( url="https://your.form.based.auth.example.com/index.php", method="POST", body={"name": "your_username", "password": "your_password", "enter": "Sign in"}, body_format="form-urlencoded", status_code=[302] ) # Example 5: Upload a file via multipart/form-multipart yield Uri( url="https://httpbin.org/post", method="POST", body={ "file1": {"filename": "/bin/true", "mime_type": "application/octet-stream", "multipart_encoding": "base64"}, "file2": {"content": "text based file content", "filename": "fake.txt", "mime_type": "text/plain", "multipart_encoding": "7or8bit"}, "text_form_field": "value" }, body_format="form-multipart" ) # Example 6: Connect to a website using a previously stored cookie yield Uri( url="https://your.form.based.auth.example.com/dashboard.php", method="GET", headers={"Cookie": "session_id=abc123"} # Replace with actual cookie string ) # Example 7: Queue a build of a project in Jenkins yield Uri( url=f"http://{jenkins_host}/job/{jenkins_job}/build?token={jenkins_token}", method="GET", url_username="your_jenkins_user", url_password="your_jenkins_password", force_basic_auth=True, status_code=[201] ) # Example 8: POST from contents of a local file yield Uri( url="https://httpbin.org/post", method="POST", src="file.json" ) # Example 9: Provide SSL/TLS ciphers as a list yield Uri( url="https://example.org", method="GET", ciphers=[ "@SECLEVEL=2", "ECDH+AESGCM", "ECDH+CHACHA20", "ECDH+AES", "DHE+AES", "!aNULL", "!eNULL", "!aDSS", "!SHA1", "!AESCCM" ] )
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
- class reemote.operations.builtin.find.Find(paths: list, age: str = None, age_stamp: str = 'mtime', checksum_algorithm: str = 'sha1', contains: str = None, depth: int = None, encoding: str = 'utf-8', exact_mode: bool = True, excludes: list = None, file_type: str = 'file', follow: bool = False, get_checksum: bool = False, hidden: bool = False, limit: int = None, mode: str = None, patterns: list = None, read_whole_file: bool = False, recurse: bool = False, size: str = None, use_regex: bool = False)[source]¶
Bases:
objectA class to encapsulate the functionality of finding files based on specific criteria. This mimics the ansible.builtin.find module behavior, allowing users to search for files based on various criteria like age, size, patterns, etc.
- paths¶
List of paths to search in.
- Type:
list
- age¶
Select files whose age is equal to or greater than the specified time.
- Type:
str
- age_stamp¶
Choose the file property against which we compare age (atime, ctime, mtime).
- Type:
str
- checksum_algorithm¶
Algorithm to determine checksum of file.
- Type:
str
- contains¶
A regular expression or pattern to match against file content.
- Type:
str
- depth¶
Set the maximum number of levels to descend into.
- Type:
int
- encoding¶
Encoding of files when doing contains search.
- Type:
str
- exact_mode¶
Restrict mode matching to exact matches only.
- Type:
bool
- excludes¶
Patterns to exclude from matches.
- Type:
list
- file_type¶
Type of file to select (any, directory, file, link).
- Type:
str
- follow¶
Whether to follow symlinks.
- Type:
bool
- get_checksum¶
Whether to return a checksum of the file.
- Type:
bool
Include hidden files.
- Type:
bool
- limit¶
Limit the maximum number of matching paths returned.
- Type:
int
- mode¶
Choose objects matching specified permission.
- Type:
str
- patterns¶
Patterns to match file basenames.
- Type:
list
- read_whole_file¶
Whether to read whole file for contains search.
- Type:
bool
- recurse¶
Recursively descend into directories.
- Type:
bool
- size¶
Select files by size.
- Type:
str
- use_regex¶
Whether patterns are regex or shell globs.
- Type:
bool
Examples:
# Recursively find /tmp files older than 2 days r = yield Find(paths=["/tmp"], age="2d", recurse=True) print(r.cp.files) # Find /var/log files equal or greater than 10 megabytes ending with .old or .log.gz r = yield Find(paths=["/var/log"], patterns=["*.old", "*.log.gz"], size="10m") print(r.cp.files)
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
This implementation uses the ansible find module under the hood
Multiple criteria are AND’d together
- class reemote.operations.builtin.apt.Apt(name: list = None, state: str = 'present', allow_change_held_packages: bool = False, allow_downgrade: bool = False, allow_unauthenticated: bool = False, auto_install_module_deps: bool = True, autoclean: bool = False, autoremove: bool = False, cache_valid_time: int = 0, clean: bool = False, deb: str = None, default_release: str = None, dpkg_options: str = 'force-confdef,force-confold', fail_on_autoremove: bool = False, force: bool = False, force_apt_get: bool = False, install_recommends: bool = None, lock_timeout: int = 60, only_upgrade: bool = False, policy_rc_d: int = None, purge: bool = False, update_cache: bool = False, update_cache_retries: int = 5, update_cache_retry_max_delay: int = 12, upgrade: str = 'no', guard: bool = True, sudo: bool = False, su: bool = False)[source]¶
Bases:
objectApt. A class to encapsulate the functionality of apt package management in Debian/Ubuntu systems. It generates appropriate apt commands that can be passed to the Shell class for execution.
- name¶
A list of package names, like
['foo'], or a package specifier with version, like['foo=1.0'].- Type:
list
- state¶
Indicates the desired package state. Choices:
"absent","build-dep","latest","present","fixed".- Type:
str
- allow_change_held_packages¶
Allows changing the version of a package which is on the apt hold list.
- Type:
bool
- allow_downgrade¶
Corresponds to the
--allow-downgradesoption for apt.- Type:
bool
- allow_unauthenticated¶
Ignore if packages cannot be authenticated.
- Type:
bool
- auto_install_module_deps¶
Automatically install dependencies required to run this module.
- Type:
bool
- autoclean¶
If true, cleans the local repository of retrieved package files (
apt-get autoclean).- Type:
bool
- autoremove¶
If true, remove unused dependency packages (
apt-get autoremove).- Type:
bool
- cache_valid_time¶
Update the apt cache if it is older than this time in seconds.
- Type:
int
- clean¶
Run the equivalent of
apt-get cleanto clear out the local repository.- Type:
bool
- deb¶
Path to a
.debpackage on the remote machine.- Type:
str
- default_release¶
Corresponds to the
-toption for apt and sets pin priorities.- Type:
str
- dpkg_options¶
Add dpkg options to the apt command.
- Type:
str
- fail_on_autoremove¶
Corresponds to the
--no-removeoption for apt.- Type:
bool
- force¶
Corresponds to the
--force-yesto apt-get (destructive operation).- Type:
bool
- force_apt_get¶
Force usage of
apt-getinstead ofaptitude.- Type:
bool
- install_recommends¶
Whether to install recommended packages.
- Type:
bool
- lock_timeout¶
Seconds to wait to acquire a lock on the apt db.
- Type:
int
- only_upgrade¶
Only upgrade a package if it is already installed.
- Type:
bool
- policy_rc_d¶
Force the exit code of
/usr/sbin/policy-rc.d.- Type:
int
- purge¶
Will force purging of configuration files if
state="absent"orautoremove=True.- Type:
bool
- update_cache¶
Run
apt-get updatebefore the operation.- Type:
bool
- update_cache_retries¶
Number of retries if the cache update fails.
- Type:
int
- update_cache_retry_max_delay¶
Max delay for exponential backoff during cache update retries.
- Type:
int
- upgrade¶
Type of upgrade to perform. Choices:
"dist","full","no","safe","yes".- Type:
str
- guard¶
If
False, the commands will not be executed.- Type:
bool
- sudo¶
If
True, execute commands withsudoprivileges.- Type:
bool
- su¶
If
True, execute commands withsuprivileges.- Type:
bool
Examples
Install apache httpd (state=”present” is the default):
yield Apt( name="apache2", state="present", )
Update repositories cache and install the “foo” package:
yield Apt( name="foo", update_cache=True, )
Remove the “foo” package:
yield Apt( name="foo", state="absent", )
Install a list of packages:
yield Apt( name=["foo", "foo-tools"], )
Install a specific version of a package:
yield Apt( name="foo=1.00", )
Update cache and upgrade “nginx” from a specific release:
yield Apt( name="nginx", state="latest", default_release="squeeze-backports", update_cache=True, )
Install a specific version of “nginx”, allowing downgrades:
yield Apt( name="nginx=1.18.0", state="present", allow_downgrade=True, )
Install a package without removing conflicting packages:
yield Apt( name="zfsutils-linux", state="latest", fail_on_autoremove=True, )
Install a package without its recommended dependencies:
yield Apt( name="openjdk-6-jdk", state="latest", install_recommends=False, )
Update all packages to their latest version:
yield Apt( name="*", state="latest", )
Upgrade the OS (equivalent to apt-get dist-upgrade):
yield Apt( upgrade="dist", )
Run apt-get update as a standalone operation:
yield Apt( update_cache=True, )
Update the cache only if it’s older than 3600 seconds:
yield Apt( update_cache=True, cache_valid_time=3600, )
Pass custom options to dpkg during an upgrade:
yield Apt( upgrade="dist", update_cache=True, dpkg_options="force-confold,force-confdef", )
Install a local .deb package:
yield Apt( deb="/tmp/mypackage.deb", )
Install a
.debpackage from a URL:yield Apt( deb="https://example.com/python-ppq_0.1-1_all.deb ", )
Install the build dependencies for a package:
yield Apt( name="foo", state="build-dep", )
Remove useless packages from the cache (autoclean):
yield Apt( autoclean=True, )
Remove dependencies that are no longer required (autoremove):
yield Apt( autoremove=True, )
Autoremove packages and purge their configuration files:
yield Apt( autoremove=True, purge=True, )
Clear the entire local package cache (clean):
yield Apt( clean=True, )
- class reemote.operations.builtin.debconf.Debconf(name: str, question: str = None, value=None, vtype: str = None, unseen: bool = False)[source]¶
Bases:
objectA class to configure a .deb package using debconf-set-selections or query existing selections.
This class allows users to pre-configure Debian packages by setting debconf database values, which is commonly used before package installation. It supports various value types including passwords, multiselect, boolean, etc.
- name¶
Name of package to configure.
- Type:
str
- question¶
A debconf configuration setting/question.
- Type:
str, optional
- value¶
Value to set the configuration to.
- Type:
any, optional
- vtype¶
The type of the value supplied.
- Type:
str, optional
- unseen¶
Do not set seen flag when pre-seeding.
- Type:
bool
Examples
# Set default locale to fr_FR.UTF-8 r = yield Debconf( name="locales", question="locales/default_environment_locale", value="fr_FR.UTF-8", vtype="select" ) # Set to generate locales r = yield Debconf( name="locales", question="locales/locales_to_be_generated", value="en_US.UTF-8 UTF-8, fr_FR.UTF-8 UTF-8", vtype="multiselect" ) # Accept oracle license r = yield Debconf( name="oracle-java7-installer", question="shared/accepted-oracle-license-v1-1", value=True, vtype="select" ) # Query existing selections for a package r = yield Debconf(name="tzdata") # Pre-configure tripwire site passphrase r = yield Debconf( name="tripwire", question="tripwire/site-passphrase", value="my_secret_passphrase", vtype="password" )
Notes
This class requires the debconf and debconf-utils packages to be installed on the target system.
For sensitive data like passwords, ensure the task uses appropriate security measures.
This module only updates the debconf database; an additional step is needed to reconfigure the package.
Setting passwords may always show as changed due to debconf-get-selections masking passwords.
- VALID_VTYPES = ['boolean', 'error', 'multiselect', 'note', 'password', 'seen', 'select', 'string', 'text', 'title']¶
- class reemote.operations.builtin.command.AnsibleCommand(cmd: str = None, argv: list = None, chdir: str = None, creates: str = None, expand_argument_vars: bool = True, removes: str = None, stdin: str = None, stdin_add_newline: bool = True, strip_empty_ends: bool = True, guard: bool = True, sudo: bool = False, su: bool = False)[source]¶
Bases:
objectA class to encapsulate the functionality of executing commands on remote targets, similar to Ansible’s builtin.command module.
This class executes commands on all selected nodes without processing through the shell. Operations like “*”, “<”, “>”, “|”, “;” and “&” will not work. Use Shell class for these features.
- cmd¶
The command to run.
- Type:
str
- argv¶
Passes the command as a list rather than a string.
- Type:
list
- chdir¶
Change into this directory before running the command.
- Type:
str
- creates¶
A filename or glob pattern. If a matching file already exists, this step will not be run.
- Type:
str
- expand_argument_vars¶
Expands the arguments that are variables.
- Type:
bool
- removes¶
A filename or glob pattern. If a matching file exists, this step will be run.
- Type:
str
- stdin¶
Set the stdin of the command directly to the specified value.
- Type:
str
- stdin_add_newline¶
If set to true, append a newline to stdin data.
- Type:
bool
- strip_empty_ends¶
Strip empty lines from the end of stdout/stderr in result.
- Type:
bool
- guard¶
If False the commands will not be executed.
- Type:
bool
- sudo¶
If True, the commands will be executed with sudo privileges.
- Type:
bool
- su¶
If True, the commands will be executed with su privileges.
- Type:
bool
Examples:
# Execute a simple command r = yield AnsibleCommand("cat /etc/motd") print(r.cp.stdout) # Execute command with creates condition r = yield AnsibleCommand("/usr/bin/make_database.sh db_user db_name", creates="/path/to/database") # Execute command with argv r = yield AnsibleCommand(argv=["/usr/bin/make_database.sh", "Username with whitespace", "dbname with whitespace"], creates="/path/to/database") # Execute command with chdir r = yield AnsibleCommand("/usr/bin/make_database.sh db_user db_name", chdir="somedir/", creates="/path/to/database")
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
Commands are constructed based on the sudo, and su flags.
If you want to run a command through the shell, use the Shell class instead.
creates, removes, and chdir can be specified to control when commands are executed.
- class reemote.operations.builtin.reboot.Reboot(boot_time_command: str = 'cat /proc/sys/kernel/random/boot_id', connect_timeout: int = None, msg: str = 'Reboot initiated by Ansible', post_reboot_delay: int = 0, pre_reboot_delay: int = 0, reboot_command: str = None, reboot_timeout: int = 600, search_paths: list = ['/sbin', '/bin', '/usr/sbin', '/usr/bin', '/usr/local/sbin'], test_command: str = 'whoami')[source]¶
Bases:
objectA class to encapsulate the functionality of rebooting machines in Unix-like operating systems. It allows users to specify various reboot parameters such as delays, messages, custom commands, and timeout settings. The class waits for the machine to go down, come back up, and respond to commands.
- boot_time_command¶
Command to run that returns a unique string indicating the last time the system was booted.
- Type:
str
- connect_timeout¶
Maximum seconds to wait for a successful connection to the managed hosts before trying again.
- Type:
int
- msg¶
Message to display to users before reboot.
- Type:
str
- post_reboot_delay¶
Seconds to wait after the reboot command was successful before attempting to validate the system rebooted successfully.
- Type:
int
- pre_reboot_delay¶
Seconds to wait before reboot. Passed as a parameter to the reboot command.
- Type:
int
- reboot_command¶
Command to run that reboots the system, including any parameters passed to the command.
- Type:
str
- reboot_timeout¶
Maximum seconds to wait for machine to reboot and respond to a test command.
- Type:
int
- search_paths¶
Paths to search on the remote machine for the shutdown command.
- Type:
list
- test_command¶
Command to run on the rebooted host and expect success from to determine the machine is ready for further tasks.
- Type:
str
Examples:
# Unconditionally reboot the machine with all defaults r = yield Reboot() # Reboot a slow machine that might have lots of updates to apply r = yield Reboot(reboot_timeout=3600) # Reboot a machine with shutdown command in unusual place r = yield Reboot(search_paths=['/lib/molly-guard']) # Reboot machine using a custom reboot command r = yield Reboot( reboot_command="launchctl reboot userspace", boot_time_command="uptime | cut -d ' ' -f 5" ) # Reboot machine and send a message r = yield Reboot(msg="Rebooting machine in 5 seconds")
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
PATH is ignored on the remote node when searching for the shutdown command. Use search_paths to specify locations to search if the default paths do not work.
For Windows targets, use the ansible.windows.win_reboot module instead.
- class reemote.operations.builtin.tempfile.Tempfile(state: str = 'file', path: str = None, prefix: str = 'ansible.', suffix: str = '', guard: bool = True, sudo: bool = False, su: bool = False)[source]¶
Bases:
objectA class to encapsulate the functionality of creating temporary files and directories. This class mimics the behavior of the ansible.builtin.tempfile module, creating temporary files or directories with customizable prefix, suffix, and location.
- path¶
Location where temporary file or directory should be created. If not specified, the default system temporary directory will be used.
- Type:
str
- prefix¶
Prefix of file/directory name created by module.
- Type:
str
- suffix¶
Suffix of file/directory name created by module.
- Type:
str
- state¶
Whether to create file or directory. Choices are “file” or “directory”.
- Type:
str
- guard¶
If False the commands will not be executed.
- Type:
bool
- sudo¶
If True, the commands will be executed with sudo privileges.
- Type:
bool
- su¶
If True, the commands will be executed with su privileges.
- Type:
bool
Examples:
# Create temporary build directory r = yield Tempfile(state="directory", suffix="build") # Create temporary file r = yield Tempfile(state="file", suffix="temp") # The path is available in the result print(r.path) # Create a temporary file with a specific prefix r = yield Tempfile(state="file", suffix="txt", prefix="myfile_")
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
Files/directories created are accessible only by creator.
For world-accessible files, use the File class after creation.
Commands are constructed based on the sudo, and su flags.
- class reemote.operations.builtin.slurp.Slurp(src: str, guard: bool = True)[source]¶
Bases:
objectA class to encapsulate the functionality of the ansible.builtin.slurp module. It fetches a base64-encoded blob containing the data in a remote file.
This module works like ansible.builtin.fetch but returns base64-encoded content. It is used for fetching files from remote nodes and is supported for both Unix-like and Windows targets.
- src¶
The file on the remote system to fetch. This must be a file, not a directory.
- Type:
str
- guard¶
If False the commands will not be executed.
- Type:
bool
Examples:
# Fetch a file from remote nodes r = yield Slurp(src="/proc/mounts") # The result contains base64-encoded content print(r.cp.content) # Decode the content import base64 decoded_content = base64.b64decode(r.cp.content).decode('utf-8') print(decoded_content)
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
This module returns an ‘in memory’ base64 encoded version of the file
This will require at least twice the RAM as the original file size
The src parameter is required and must point to a file, not a directory
- class reemote.operations.builtin.add_host.AddHost(name: str = None, hostname: str = None, groups=None, group=None, groupname=None, **kwargs)[source]¶
Bases:
objectA class to encapsulate the functionality of adding hosts to the in-memory inventory similar to Ansible’s ansible.builtin.add_host module.
This allows dynamic addition of hosts and groups to the inventory during playbook execution, making them available for use in subsequent plays.
- name¶
The hostname/ip of the host to add to the inventory, can include a colon and a port number.
- Type:
str
- groups¶
The groups to add the hostname to.
- Type:
list
- \*\*kwargs
Additional variables to assign to the host.
Examples:
# Add a host to a group with custom variables yield AddHost(name='192.168.1.100', groups=['web_servers'], foo=42) # Add a host to multiple groups yield AddHost(hostname='192.168.1.101', groups=['group1', 'group2']) # Add a host with non-standard port yield AddHost(name='192.168.1.102:2222') # Add a host with tunnel configuration yield AddHost(hostname='192.168.1.103', ansible_host='localhost', ansible_port=2222)
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
Hosts added will not bypass the –limit from the command line
The host is available from hostvars and for delegation as a normal part of the inventory
Changed status is provided as it can be useful for tracking inventory changes
- class reemote.operations.builtin.git.Git(repo: str, dest: str, version: str = 'HEAD', accept_hostkey: bool = False, accept_newhostkey: bool = False, archive: str = None, archive_prefix: str = None, bare: bool = False, clone: bool = True, depth: int = None, executable: str = None, force: bool = False, gpg_allowlist: list = None, key_file: str = None, recursive: bool = True, reference: str = None, refspec: str = None, remote: str = 'origin', separate_git_dir: str = None, single_branch: bool = False, ssh_opts: str = None, track_submodules: bool = False, umask: str = None, update: bool = True, verify_commit: bool = False, guard: bool = True, sudo: bool = False, su: bool = False)[source]¶
Bases:
objectA class to encapsulate the functionality of git operations in Unix-like operating systems. It allows users to manage git checkouts of repositories to deploy files or software.
This class provides a Python interface to common git operations such as cloning, checking out specific versions, handling submodules, and creating archives.
- repo¶
Git, SSH, or HTTP(S) protocol address of the git repository.
- Type:
str
- dest¶
The path of where the repository should be checked out.
- Type:
str
- version¶
What version of the repository to check out.
- Type:
str
- accept_hostkey¶
Will ensure -o StrictHostKeyChecking=no is present as an ssh option.
- Type:
bool
- accept_newhostkey¶
Use -o StrictHostKeyChecking=accept-new as an ssh option.
- Type:
bool
- archive¶
Specify archive file path with extension.
- Type:
str
- archive_prefix¶
Specify a prefix to add to each file path in archive.
- Type:
str
- bare¶
If true, repository will be created as a bare repo.
- Type:
bool
- clone¶
If false, do not clone the repository even if it does not exist locally.
- Type:
bool
- depth¶
Create a shallow clone with a history truncated to the specified number.
- Type:
int
- executable¶
Path to git executable to use.
- Type:
str
- force¶
If true, any modified files in the working repository will be discarded.
- Type:
bool
- gpg_allowlist¶
List of trusted GPG fingerprints.
- Type:
list
- key_file¶
Specify an optional private key file path.
- Type:
str
- recursive¶
If false, repository will be cloned without the –recursive option.
- Type:
bool
- reference¶
Reference repository.
- Type:
str
- refspec¶
Add an additional refspec to be fetched.
- Type:
str
- remote¶
Name of the remote.
- Type:
str
- separate_git_dir¶
The path to place the cloned repository.
- Type:
str
- single_branch¶
Clone only the history leading to the tip of the specified revision.
- Type:
bool
- ssh_opts¶
Options git will pass to ssh when used as protocol.
- Type:
str
- track_submodules¶
If true, submodules will track the latest commit.
- Type:
bool
- umask¶
The umask to set before doing any checkouts.
- Type:
str
- update¶
If false, do not retrieve new revisions from the origin repository.
- Type:
bool
- verify_commit¶
If true, verify the signature of a GPG signed commit.
- Type:
bool
- guard¶
If False the commands will not be executed.
- Type:
bool
- sudo¶
If True, the commands will be executed with sudo privileges.
- Type:
bool
- su¶
If True, the commands will be executed with su privileges.
- Type:
bool
Examples:
# Git checkout r = yield Git( repo='https://github.com/ansible/ansible.git', dest='/tmp/checkout', version='release-0.22' ) print(r.cp.stdout) # Read-write git checkout from github r = yield Git( repo='[email protected]:ansible/ansible.git', dest='/tmp/checkout' ) # Just ensuring the repo checkout exists r = yield Git( repo='https://github.com/ansible/ansible.git', dest='/tmp/checkout', update=False ) # Create git archive from repo r = yield Git( repo='[email protected]:ansible/ansible.git', dest='/tmp/checkout', archive='/tmp/ansible.zip' )
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
Commands are constructed based on the various git options and flags.
If the task seems to be hanging, first verify remote host is in known_hosts.
- class reemote.operations.builtin.user.User(name: str, state: str = 'present', uid: int = None, group: str = None, groups: list = None, append: bool = False, comment: str = None, home: str = None, shell: str = None, password: str = None, create_home: bool = True, move_home: bool = False, system: bool = False, force: bool = False, remove: bool = False, generate_ssh_key: bool = False, ssh_key_bits: int = None, ssh_key_file: str = None, ssh_key_comment: str = None, ssh_key_passphrase: str = None, ssh_key_type: str = 'rsa', update_password: str = 'always', expires: float = None, password_lock: bool = None, password_expire_max: int = None, password_expire_min: int = None, password_expire_warn: int = None, password_expire_account_disable: int = None, local: bool = False, skeleton: str = None, umask: str = None, uid_min: int = None, uid_max: int = None, seuser: str = None, login_class: str = None, authorization: str = None, role: str = None, profile: str = None, hidden: bool = None)[source]¶
Bases:
objectA class to encapsulate the functionality of managing user accounts in Unix-like operating systems. It allows users to create, modify, and remove user accounts with various attributes and options.
- name¶
Name of the user to create, remove or modify.
- Type:
str
- state¶
Whether the account should exist or not (‘present’ or ‘absent’).
- Type:
str
- uid¶
Optionally sets the UID of the user.
- Type:
int
- group¶
Optionally sets the user’s primary group.
- Type:
str
- groups¶
A list of supplementary groups which the user is also a member of.
- Type:
list
- append¶
If true, add the user to the groups specified in groups.
- Type:
bool
- comment¶
Optionally sets the description (aka GECOS) of user account.
- Type:
str
- home¶
Optionally set the user’s home directory.
- Type:
str
- shell¶
Optionally set the user’s shell.
- Type:
str
- password¶
If provided, set the user’s password.
- Type:
str
- create_home¶
Whether to create a home directory for the user.
- Type:
bool
- move_home¶
If set to true when used with home, attempt to move the user’s old home directory.
- Type:
bool
- system¶
When creating an account, setting this to true makes the user a system account.
- Type:
bool
- force¶
Forces removal of the user and associated directories.
- Type:
bool
- remove¶
Attempts to remove directories associated with the user.
- Type:
bool
- generate_ssh_key¶
Whether to generate a SSH key for the user.
- Type:
bool
- ssh_key_bits¶
Optionally specify number of bits in SSH key to create.
- Type:
int
- ssh_key_file¶
Optionally specify the SSH key filename.
- Type:
str
- ssh_key_comment¶
Optionally define the comment for the SSH key.
- Type:
str
- ssh_key_passphrase¶
Set a passphrase for the SSH key.
- Type:
str
- ssh_key_type¶
Optionally specify the type of SSH key to generate.
- Type:
str
- update_password¶
Controls when to update passwords (‘always’ or ‘on_create’).
- Type:
str
- expires¶
An expiry time for the user in epoch.
- Type:
float
- password_lock¶
Lock the password.
- Type:
bool
- password_expire_max¶
Maximum number of days between password change.
- Type:
int
- password_expire_min¶
Minimum number of days between password change.
- Type:
int
- password_expire_warn¶
Number of days of warning before password expires.
- Type:
int
- password_expire_account_disable¶
Number of days after a password expires until the account is disabled.
- Type:
int
- local¶
Forces the use of “local” command alternatives.
- Type:
bool
- skeleton¶
Optionally set a home skeleton directory.
- Type:
str
- umask¶
Sets the umask of the user.
- Type:
str
- uid_min¶
Sets the UID_MIN value for user creation.
- Type:
int
- uid_max¶
Sets the UID_MAX value for user creation.
- Type:
int
- seuser¶
Optionally sets the seuser type on SELinux enabled systems.
- Type:
str
- login_class¶
Optionally sets the user’s login class.
- Type:
str
- authorization¶
Sets the authorization of the user.
- Type:
str
- role¶
Sets the role of the user.
- Type:
str
- profile¶
Sets the profile of the user.
- Type:
str
Optionally hide the user from the login window and system preferences (macOS only).
- Type:
bool
Examples:
# Add the user 'johnd' with a specific uid and a primary group of 'admin' r = yield User(name="johnd", comment="John Doe", uid=1040, group="admin") # Create a user 'johnd' with a home directory r = yield User(name="johnd", create_home=True) # Add the user 'james' with a bash shell, appending the group 'admins' and 'developers' r = yield User(name="james", shell="/bin/bash", groups=["admins", "developers"], append=True) # Remove the user 'johnd' r = yield User(name="johnd", state="absent", remove=True) # Create a 2048-bit SSH key for user jsmith r = yield User(name="jsmith", generate_ssh_key=True, ssh_key_bits=2048, ssh_key_file=".ssh/id_rsa")
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
Commands are constructed based on the provided parameters and the target operating system.
The implementation uses underlying system tools like useradd, usermod, userdel, pw, dscl depending on the platform.
- class reemote.operations.builtin.assert.Assert(that: list, fail_msg: str = None, success_msg: str = None, quiet: bool = False)[source]¶
Bases:
objectA class to encapsulate the functionality of asserting expressions in Ansible-style fashion. It allows users to specify expressions that must evaluate to true, with optional custom messages for both success and failure cases. The module supports quiet mode to reduce output verbosity.
- that¶
A list of string expressions to evaluate.
- Type:
list
- fail_msg¶
Custom message to display on assertion failure.
- Type:
str
- success_msg¶
Custom message to display on assertion success.
- Type:
str
- quiet¶
If True, suppresses verbose output.
- Type:
bool
Examples:
# Simple assertion yield Assert(that=["ansible_os_family != 'RedHat'"]) # Multiple conditions with custom messages yield Assert( that=[ "my_param <= 100", "my_param >= 0" ], fail_msg="'my_param' must be between 0 and 100", success_msg="'my_param' is between 0 and 100" ) # Quiet mode to reduce output yield Assert( that=["my_param <= 100", "my_param >= 0"], quiet=True )
- Usage:
This class is designed to be used in a generator-based workflow where assertions are yielded for evaluation.
Notes
Expressions follow the same syntax as Ansible’s when statements.
Both fail_msg and success_msg support templating.
The quiet parameter can be used to minimize output in large-scale deployments.
- class reemote.operations.builtin.unarchive.Unarchive(src: str, dest: str, copy: bool = True, remote_src: bool = False, creates: str = None, exclude: list = None, extra_opts: list = None, include: list = None, keep_newer: bool = False, list_files: bool = False, owner: str = None, group: str = None, mode: str = None, attributes: str = None, seuser: str = None, serole: str = None, setype: str = None, selevel: str = None, unsafe_writes: bool = False, decrypt: bool = True, validate_certs: bool = True, io_buffer_size: int = 65536)[source]¶
Bases:
objectA class to encapsulate the functionality of unpacking archives in Unix-like operating systems. It allows users to specify an archive file that is unpacked on all hosts, with various options for controlling the extraction process.
- src¶
Path to the archive file to unpack.
- Type:
str
- dest¶
Remote absolute path where the archive should be unpacked.
- Type:
str
- copy¶
If true, the file is copied from local controller to the managed node.
- Type:
bool
- remote_src¶
Set to true to indicate the archived file is already on the remote system.
- Type:
bool
- creates¶
If the specified path already exists, this step will not be run.
- Type:
str
- exclude¶
List of directory and file entries to exclude from extraction.
- Type:
list
- extra_opts¶
Additional options to pass to the extraction command.
- Type:
list
- include¶
List of directory and file entries to extract (only these will be extracted).
- Type:
list
- keep_newer¶
Do not replace existing files that are newer than files from the archive.
- Type:
bool
- list_files¶
If set to True, return the list of files contained in the archive.
- Type:
bool
- owner¶
Name of the user that should own the extracted files.
- Type:
str
- group¶
Name of the group that should own the extracted files.
- Type:
str
- mode¶
Permissions for the extracted files.
- Type:
str
- attributes¶
Filesystem attributes for the extracted files.
- Type:
str
- seuser¶
SELinux user context.
- Type:
str
- serole¶
SELinux role context.
- Type:
str
- setype¶
SELinux type context.
- Type:
str
- selevel¶
SELinux level context.
- Type:
str
- unsafe_writes¶
Allow unsafe writes if atomic operations fail.
- Type:
bool
- decrypt¶
Control auto-decryption of source files using vault.
- Type:
bool
- validate_certs¶
Validate SSL certificates when downloading from HTTPS URLs.
- Type:
bool
- io_buffer_size¶
Size of memory buffer for extracting files.
- Type:
int
Examples:
# Extract a local archive file to a remote destination r = yield Unarchive(src="foo.tgz", dest="/var/lib/foo") print(r.dest) # Unarchive a file that is already on the remote machine r = yield Unarchive(src="/tmp/foo.zip", dest="/usr/local/bin", remote_src=True) # Unarchive with extra options r = yield Unarchive( src="/tmp/foo.zip", dest="/usr/local/bin", extra_opts=["--transform", "s/^xxx/yyy/"] )
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
Requires zipinfo and gtar/unzip command on target host.
Can handle .zip, .tar, .tar.gz, .tar.bz2, .tar.xz, and .tar.zst files.
Does not handle compressed files that don’t contain archives (.gz, .bz2, .xz, .zst without tar).
- class reemote.operations.builtin.getent.GetEnt(database: str, key: str = None, fail_key: bool = True, service: str = None, split: str = None)[source]¶
Bases:
objectA class to encapsulate the functionality of the Unix getent utility. It allows users to query system databases such as passwd, group, hosts, etc.
- database¶
The name of a getent database supported by the target system (passwd, group, hosts, etc).
- Type:
str
- key¶
Key from which to return values from the specified database, otherwise the full contents are returned.
- Type:
str, optional
- fail_key¶
If a supplied key is missing this will make the task fail if true. Default is True.
- Type:
bool
- service¶
Override all databases with the specified service. Requires system support.
- Type:
str, optional
- split¶
Character used to split the database values into lists/arrays such as ‘:’ or ‘t’.
- Type:
str, optional
Examples:
# Get root user info r = yield GetEnt(database="passwd", key="root") # Access the result print(r.facts.getent_passwd) # Get all groups r = yield GetEnt(database="group", split=":") # Access the result print(r.facts.getent_group) # Get http service info, no error if missing r = yield GetEnt(database="services", key="http", fail_key=False) # Access the result print(r.facts.getent_services)
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution. The results are available in the facts dictionary under getent_<database> keys.
Notes
Not all databases support enumeration, check system documentation for details
Commands are constructed based on the provided parameters
Results are returned in ansible_facts format for consistency with Ansible behavior
- class reemote.operations.builtin.file.File(path: str, state: str = None, owner: str = None, group: str = None, mode: str = None, src: str = None, dest: str = None, name: str = None, recurse: bool = False, force: bool = False, follow: bool = True, unsafe_writes: bool = False, seuser: str = None, serole: str = None, setype: str = None, selevel: str = None, attributes: str = None, attr: str = None, modification_time: str = None, access_time: str = None, modification_time_format: str = '%Y%m%d%H%M.%S', access_time_format: str = '%Y%m%d%H%M.%S', guard: bool = True)[source]¶
Bases:
objectA class to manage files and file properties on Unix-like operating systems. This class provides functionality similar to Ansible’s builtin.file module, allowing management of file attributes, permissions, ownership, and states.
- path¶
Path to the file being managed.
- Type:
str
- state¶
Desired state of the file (absent, directory, file, hard, link, touch).
- Type:
str
- owner¶
Name of the user that should own the file.
- Type:
str
- group¶
Name of the group that should own the file.
- Type:
str
- mode¶
Permissions for the file.
- Type:
str
- src¶
Source path for links.
- Type:
str
- recurse¶
Recursively set attributes on directory contents.
- Type:
bool
- force¶
Force creation of links.
- Type:
bool
- follow¶
Follow symbolic links.
- Type:
bool
- unsafe_writes¶
Allow unsafe write operations.
- Type:
bool
- seuser¶
SELinux user context.
- Type:
str
- serole¶
SELinux role context.
- Type:
str
- setype¶
SELinux type context.
- Type:
str
- selevel¶
SELinux level context.
- Type:
str
- attributes¶
File attributes to set.
- Type:
str
- modification_time¶
Modification time to set.
- Type:
str
- access_time¶
Access time to set.
- Type:
str
- modification_time_format¶
Format for modification time.
- Type:
str
- access_time_format¶
Format for access time.
- Type:
str
- guard¶
If False, commands will not be executed.
- Type:
bool
Examples:
# Change file ownership, group and permissions yield File(path="/etc/foo.conf", owner="foo", group="foo", mode="0644") # Create a symbolic link yield File(src="/file/to/link/to", dest="/path/to/symlink", state="link") # Create a directory if it does not exist yield File(path="/etc/some_directory", state="directory", mode="0755") # Remove file (delete file) yield File(path="/etc/foo.txt", state="absent")
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
Commands are constructed based on the provided parameters and state.
Supports various file operations including creation, deletion, permission changes, and link management.
- class reemote.operations.builtin.stat.Stat(path: str, checksum_algorithm: str = 'sha1', follow: bool = False, get_attributes: bool = True, get_checksum: bool = True, get_mime: bool = True, guard: bool = True)[source]¶
Bases:
objectA class to encapsulate the functionality of retrieving file or file system status, similar to the Linux/Unix stat command. This class allows users to specify a file path and various options to control what information is retrieved about the file.
- path¶
The full path of the file/object to get the facts of.
- Type:
str
- checksum_algorithm¶
Algorithm to determine checksum of file. Choices: “md5”, “sha1”, “sha224”, “sha256”, “sha384”, “sha512”.
- Type:
str
- follow¶
Whether to follow symlinks.
- Type:
bool
- get_attributes¶
Get file attributes using lsattr tool if present.
- Type:
bool
- get_checksum¶
Whether to return a checksum of the file.
- Type:
bool
- get_mime¶
Use file magic and return data about the nature of the file.
- Type:
bool
- guard¶
If False the commands will not be executed.
- Type:
bool
Examples:
# Obtain the stats of /etc/foo.conf r = yield Stat(path="/etc/foo.conf") # Check if file exists and belongs to 'root' if r.cp.stat.exists and r.cp.stat.pw_name != 'root': print("File ownership has changed") # Check if a path is a symlink r = yield Stat(path="/path/to/something") if r.cp.stat.islnk is not defined: print("Path doesn't exist") elif r.cp.stat.islnk: print("Path exists and is a symlink") else: print("Path exists and isn't a symlink") # Check if a path is a directory r = yield Stat(path="/path/to/something") if r.cp.stat.isdir is defined and r.cp.stat.isdir: print("Path exists and is a directory") # Do not calculate the checksum r = yield Stat(path="/path/to/myhugefile", get_checksum=False) # Use sha256 to calculate the checksum r = yield Stat(path="/path/to/something", checksum_algorithm="sha256")
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
For Windows targets, use the ansible.windows.win_stat module instead.
Commands are constructed based on the provided parameters.
- class reemote.operations.builtin.dpkg_selection.DpkgSelections(name: str, selection: str, guard: bool = True)[source]¶
Bases:
objectA class to manage dpkg package selection states using dpkg –get-selections and dpkg –set-selections.
This class allows setting the selection state of a Debian package without installing/removing it. It supports standard dpkg selection states such as ‘install’, ‘hold’, ‘deinstall’, and ‘purge’.
- name¶
The name of the package.
- Type:
str
- selection¶
The desired selection state for the package. Choices: ‘install’, ‘hold’, ‘deinstall’, ‘purge’.
- Type:
str
- guard¶
If False, the command will not be executed.
- Type:
bool
Examples
# Hold a package to prevent upgrades r = yield DpkgSelections(name="python", selection="hold") print(r.cp.stdout) # Allow a package to be upgraded again r = yield DpkgSelections(name="python", selection="install") print(r.cp.stdout)
Notes
This module only changes the selection state; it does not install or remove packages. Use the apt module for actual package management.
Only works on Debian-based systems where dpkg is available.
- VALID_SELECTIONS = {'deinstall', 'hold', 'install', 'purge'}¶
- class reemote.operations.builtin.expect.Expect(command: str, responses: dict, chdir: str = None, creates: str = None, echo: bool = False, removes: str = None, timeout: int = 30, guard: bool = True)[source]¶
Bases:
objectA class to encapsulate the functionality of the ansible.builtin.expect module. Executes a command and responds to prompts using the pexpect library.
This module executes a command and responds to prompts. The given command will be executed on all selected nodes. It will not be processed through the shell, so variables like $HOME and operations like “<”, “>”, “|”, and “&” will not work.
- command¶
The command to run.
- Type:
str
- responses¶
Mapping of prompt regular expressions and corresponding answer(s).
- Type:
dict
- chdir¶
Change into this directory before running the command.
- Type:
str, optional
- creates¶
A filename, when it already exists, this step will not be run.
- Type:
str, optional
- echo¶
Whether or not to echo out your response strings.
- Type:
bool
- removes¶
A filename, when it does not exist, this step will not be run.
- Type:
str, optional
- timeout¶
Amount of time in seconds to wait for the expected strings.
- Type:
int, optional
- guard¶
If False the commands will not be executed.
- Type:
bool
Examples:
# Case insensitive password string match r = yield Expect( command="passwd username", responses={"(?i)password": "MySekretPa$$word"}, guard=True ) # Match multiple regular expressions with individual responses r = yield Expect( command="/path/to/custom/command", responses={ "Question": ["response1", "response2", "response3"], "^Match another prompt$": "response" } )
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
If you want to run a command through the shell, you must specify a shell in the command.
Case insensitive searches are indicated with a prefix of (?i).
The pexpect library operates with a search window of 2000 bytes.
For more complex scenarios, consider using expect code with Shell or Script modules.
- class reemote.operations.builtin.template.Template(src='', dest='', vars=None, backup=False, force=True, lstrip_blocks=False, trim_blocks=True, newline_sequence='\n', output_encoding='utf-8', block_start_string='{%', block_end_string='%}', variable_start_string='{{', variable_end_string='}}', comment_start_string='{#', comment_end_string='#}', validate=None, attrs=None)[source]¶
Bases:
objectA class to manage builtin templating on remote servers using SFTP operations.
This class allows you to render Jinja2 templates and transfer them to remote servers. It supports template rendering with variables, backup creation, validation commands, and setting builtin attributes after transfer.
- src¶
Path to the Jinja2 template builtin on the local system.
- Type:
str
- dest¶
Path where the rendered template should be placed on the remote server.
- Type:
str
- vars¶
Variables to use when rendering the template. Defaults to
None.- Type:
dict, optional
- backup¶
Whether to create a backup of the existing builtin. Defaults to
False.- Type:
bool, optional
- force¶
Whether to replace the builtin if content differs. Defaults to
False.- Type:
bool, optional
- lstrip_blocks¶
Strip leading spaces and tabs from blocks. Defaults to
False.- Type:
bool, optional
- trim_blocks¶
Remove first newline after a block. Defaults to
False.- Type:
bool, optional
- newline_sequence¶
Newline sequence to use (’n’, ‘r’, ‘rn’). Defaults to
None.- Type:
str, optional
- output_encoding¶
Encoding for the output builtin. Defaults to
None.- Type:
str, optional
- block_start_string¶
String marking block start. Defaults to
None.- Type:
str, optional
- block_end_string¶
String marking block end. Defaults to
None.- Type:
str, optional
- variable_start_string¶
String marking variable start. Defaults to
None.- Type:
str, optional
- variable_end_string¶
String marking variable end. Defaults to
None.- Type:
str, optional
- comment_start_string¶
String marking comment start. Defaults to
None.- Type:
str, optional
- comment_end_string¶
String marking comment end. Defaults to
None.- Type:
str, optional
- validate¶
Validation command to run before final copy. Defaults to
None.- Type:
str, optional
- attrs¶
File attributes to set after writing the builtin. Defaults to
None.- Type:
dict, optional
Examples:
# Create temporary build directory yield Tempfile( state="directory", suffix="build", ) # Create temporary file yield Tempfile( state="file", suffix="temp", ) # register: tempfile_1 # Create a temporary file with a specific prefix yield Tempfile( state="file", suffix="txt", prefix="myfile_", ) # Use the registered var and the file module to remove the temporary file yield File( path="{{ tempfile_1.path }}", state="absent", ) # when: tempfile_1.path is defined
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
- class reemote.operations.builtin.hostname.Hostname(name: str, use: str = None, guard: bool = True)[source]¶
Bases:
objectA class to manage the system’s hostname on Unix-like operating systems. This class allows setting the hostname and supports different strategies for updating the hostname based on the underlying OS/distribution.
- name¶
The desired hostname to set.
- Type:
str
- use¶
Strategy to use for updating hostname.
- Type:
str
- guard¶
If False the commands will not be executed.
- Type:
bool
- Supported strategies:
“alpine”
“debian”
“freebsd”
“generic”
“macos” / “macosx” / “darwin”
“openbsd”
“openrc”
“redhat”
“sles”
“solaris”
“systemd”
Examples:
# Set a hostname r = yield Hostname(name="web01") print(r.cp.stdout) # Set a hostname specifying strategy r = yield Hostname(name="web01", use="systemd") print(r.cp.stdout)
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
This module does NOT modify /etc/hosts. You need to modify it yourself using other modules.
On macOS, this module uses scutil to set HostName, ComputerName, and LocalHostName.
Windows, HP-UX, and AIX are not currently supported.
- class reemote.operations.builtin.known_hosts.KnownHosts(name: str, key: str = None, path: str = '~/.ssh/known_hosts', state: str = 'present', hash_host: bool = False)[source]¶
Bases:
objectA class to encapsulate the functionality of managing SSH known_hosts entries. It allows users to add or remove host keys from the known_hosts file.
- name¶
The host to add or remove (must match a host specified in key).
- Type:
str
- key¶
The SSH public host key, as a string.
- Type:
str
- path¶
The known_hosts file to edit.
- Type:
str
- state¶
Whether to add (present) or remove (absent) host keys.
- Type:
str
- hash_host¶
Hash the hostname in the known_hosts file.
- Type:
bool
Examples:
# Add a host key to the system known_hosts file r = yield KnownHosts( name="foo.com.invalid", key="foo.com.invalid ssh-rsa AAAAB3NzaC1yc2E...", path="/etc/ssh/ssh_known_hosts" ) # Remove a host key r = yield KnownHosts( name="oldserver.example.com", state="absent", path="/etc/ssh/ssh_known_hosts" )
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
Starting at Ansible 2.2, multiple entries per host are allowed, but only one for each key type supported by ssh.
For custom SSH ports, both name and key need to specify the port (e.g., ‘[host.example.com]:2222’).
The known_hosts file will be created if needed, but the rest of the path must exist.
- class reemote.operations.builtin.assemble.Assemble(src: str, dest: str, delimiter: str = None, remote_src: bool = True, regexp: str = None, ignore_hidden: bool = False, backup: bool = False, decrypt: bool = True, validate: str = None, owner: str = None, group: str = None, mode: str = None, attributes: str = None, seuser: str = None, serole: str = None, setype: str = None, selevel: str = None, unsafe_writes: bool = False, guard: bool = True)[source]¶
Bases:
objectA class to encapsulate the functionality of assembling configuration files from fragments. This mimics the behavior of the ansible.builtin.assemble module, which concatenates files from a source directory to create a destination file.
Often a particular program will take a single configuration file and does not support a conf.d style structure where it is easy to build up the configuration from multiple sources. Assemble will take a directory of files that can be local or have already been transferred to the system, and concatenate them together to produce a destination file.
Files are assembled in string sorting order.
- src¶
An already existing directory full of source files.
- Type:
str
- dest¶
A file to create using the concatenation of all of the source files.
- Type:
str
- delimiter¶
A delimiter to separate the file contents.
- Type:
str
- remote_src¶
If False, it will search for src at originating/master machine. If True, it will go to the remote/target machine for the src.
- Type:
bool
- regexp¶
Assemble files only if the given regular expression matches the filename.
- Type:
str
A boolean that controls if files that start with a . will be included or not.
- Type:
bool
- backup¶
Create a backup file (if true), including the timestamp information.
- Type:
bool
- decrypt¶
This option controls the auto-decryption of source files using vault.
- Type:
bool
- validate¶
The validation command to run before copying into place.
- Type:
str
- owner¶
Name of the user that should own the filesystem object.
- Type:
str
- group¶
Name of the group that should own the filesystem object.
- Type:
str
- mode¶
The permissions the resulting filesystem object should have.
- Type:
str
- attributes¶
The attributes the resulting filesystem object should have.
- Type:
str
- seuser¶
The user part of the SELinux filesystem object context.
- Type:
str
- serole¶
The role part of the SELinux filesystem object context.
- Type:
str
- setype¶
The type part of the SELinux filesystem object context.
- Type:
str
- selevel¶
The level part of the SELinux filesystem object context.
- Type:
str
- unsafe_writes¶
Influence when to use atomic operation to prevent data corruption.
- Type:
bool
- guard¶
If False the commands will not be executed.
- Type:
bool
Examples:
# Assemble from fragments from a directory r = yield Assemble(src="/etc/someapp/fragments", dest="/etc/someapp/someapp.conf") # Insert the provided delimiter between fragments r = yield Assemble( src="/etc/someapp/fragments", dest="/etc/someapp/someapp.conf", delimiter="### START FRAGMENT ###" ) # Assemble a new "sshd_config" file into place, after passing validation with sshd r = yield Assemble( src="/etc/ssh/conf.d/", dest="/etc/ssh/sshd_config", validate="/usr/sbin/sshd -t -f %s" )
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
Files are assembled in string sorting order.
The command construction handles various file operations and validation.
- class reemote.operations.builtin.fail.Fail(msg: str = 'Failed as requested from task', guard: bool = True)[source]¶
Bases:
objectA class to encapsulate the functionality of the Ansible fail module. This module fails the progress with a custom message. It can be useful for bailing out when a certain condition is met using when.
- msg¶
The customized message used for failing execution.
- Type:
str
- guard¶
If False the commands will not be executed.
- Type:
bool
Examples:
# Fail with a custom message yield Fail("The system may not be provisioned according to the CMDB status.") # Fail with default message yield Fail()
- Usage:
This class is designed to be used in a generator-based workflow where failure conditions are yielded for execution.
Notes
This module is also supported for Windows targets.
This module has a corresponding action plugin.
- class reemote.operations.builtin.dnf5.Dnf5(name=None, state=None, allow_downgrade=False, allowerasing=False, auto_install_module_deps=True, autoremove=False, best=None, bugfix=False, cacheonly=False, conf_file=None, disable_excludes=None, disable_gpg_check=False, disable_plugin=None, disablerepo=None, download_dir=None, download_only=False, enable_plugin=None, enablerepo=None, exclude=None, install_repoquery=True, install_weak_deps=True, installroot='/', list=None, lock_timeout=30, nobest=None, releasever=None, security=False, skip_broken=False, sslverify=True, update_cache=False, update_only=False, validate_certs=True, guard=True, sudo=True)[source]¶
Bases:
objectA class to manage packages with the dnf5 package manager on Unix-like operating systems. It allows users to install, upgrade, remove, and list packages and groups with various options.
- name¶
A package name or package specifier with version.
- Type:
list
- state¶
Whether to install (present, latest), or remove (absent) a package.
- Type:
str
- allow_downgrade¶
Allow downgrading packages.
- Type:
bool
- allowerasing¶
Allow erasing of installed packages to resolve dependencies.
- Type:
bool
- auto_install_module_deps¶
Automatically install dependencies required to run this module.
- Type:
bool
- autoremove¶
Remove “leaf” packages that are no longer required.
- Type:
bool
- best¶
Use package with highest version available or fail.
- Type:
bool
- bugfix¶
Install only bugfix updates when state=latest.
- Type:
bool
- cacheonly¶
Run entirely from system cache.
- Type:
bool
- conf_file¶
Remote dnf configuration file to use.
- Type:
str
- disable_excludes¶
Disable excludes defined in DNF config files.
- Type:
str
- disable_gpg_check¶
Disable GPG checking of signatures.
- Type:
bool
- disable_plugin¶
Plugin names to disable for the operation.
- Type:
list
- disablerepo¶
Repository IDs to disable for the operation.
- Type:
list
- download_dir¶
Directory to store downloaded packages.
- Type:
str
- download_only¶
Only download packages, do not install.
- Type:
bool
- enable_plugin¶
Plugin names to enable for the operation.
- Type:
list
- enablerepo¶
Repository IDs to enable for the operation.
- Type:
list
- exclude¶
Package names to exclude when installing/updating.
- Type:
list
- install_repoquery¶
Deprecated option (no-op in DNF).
- Type:
bool
- install_weak_deps¶
Install packages linked by weak dependency relation.
- Type:
bool
- installroot¶
Alternative installroot path.
- Type:
str
- list¶
Non-idempotent commands for usage with ansible.
- Type:
str
- lock_timeout¶
Time to wait for dnf lockfile (currently no-op).
- Type:
int
- nobest¶
Opposite of best option for backwards compatibility.
- Type:
bool
- releasever¶
Alternative release version for installation.
- Type:
str
- security¶
Install only security updates when state=latest.
- Type:
bool
- skip_broken¶
Skip unavailable packages with broken dependencies.
- Type:
bool
- sslverify¶
Disable SSL validation of repository server.
- Type:
bool
- update_cache¶
Force dnf to check if cache is out of date.
- Type:
bool
- update_only¶
Only update installed packages, don’t install new ones.
- Type:
bool
- validate_certs¶
No-op parameter for compatibility.
- Type:
bool
- guard¶
If False the commands will not be executed.
- Type:
bool
- sudo¶
If True, the commands will be executed with sudo privileges.
- Type:
bool
Examples:
# Install the latest version of Apache r = yield Dnf5(name="httpd", state="latest") print(r.cp.stdout) # Install Apache >= 2.4 r = yield Dnf5(name="httpd >= 2.4", state="present") print(r.cp.stdout) # Remove the Apache package r = yield Dnf5(name="httpd", state="absent") print(r.cp.stdout) # Upgrade all packages r = yield Dnf5(name="*", state="latest") print(r.cp.stdout)
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
Commands are constructed based on the various parameters and flags.
Requires python3-libdnf5 on the target system.
- class reemote.operations.builtin.lineinfile.LineInFile(path: str, line: str = None, state: str = 'present', regexp: str = None, search_string: str = None, insertafter: str = None, insertbefore: str = None, create: bool = False, backup: bool = False, firstmatch: bool = False, backrefs: bool = False, owner: str = None, group: str = None, mode: str = None, attributes: str = None, seuser: str = None, serole: str = None, setype: str = None, selevel: str = None, unsafe_writes: bool = False, validate: str = None, guard: bool = True, sudo: bool = False, su: bool = False)[source]¶
Bases:
objectA class to encapsulate the functionality of managing lines in text files, similar to Ansible’s lineinfile module. This class ensures a particular line is present or absent in a file, with support for regular expressions, backups, and various file attributes.
- path¶
The file to modify.
- Type:
str
- line¶
The line to insert/replace into the file.
- Type:
str
- state¶
Whether the line should be there or not (“present” or “absent”).
- Type:
str
- regexp¶
The regular expression to look for in every line of the file.
- Type:
str
- search_string¶
The literal string to look for in every line of the file.
- Type:
str
- insertafter¶
Insert line after the last match of specified regular expression.
- Type:
str
- insertbefore¶
Insert line before the last match of specified regular expression.
- Type:
str
- create¶
If specified, the file will be created if it does not already exist.
- Type:
bool
- backup¶
Create a backup file including the timestamp information.
- Type:
bool
- firstmatch¶
Work with the first line that matches the given regular expression.
- Type:
bool
- backrefs¶
If set, line can contain backreferences that will get populated.
- Type:
bool
- owner¶
Name of the user that should own the filesystem object.
- Type:
str
- group¶
Name of the group that should own the filesystem object.
- Type:
str
- mode¶
The permissions the resulting filesystem object should have.
- Type:
str
- attributes¶
The attributes the resulting filesystem object should have.
- Type:
str
- seuser¶
The user part of the SELinux filesystem object context.
- Type:
str
- serole¶
The role part of the SELinux filesystem object context.
- Type:
str
- setype¶
The type part of the SELinux filesystem object context.
- Type:
str
- selevel¶
The level part of the SELinux filesystem object context.
- Type:
str
- unsafe_writes¶
Influence when to use atomic operation.
- Type:
bool
- validate¶
The validation command to run before copying the updated file.
- Type:
str
- guard¶
If False the commands will not be executed.
- Type:
bool
- sudo¶
If True, the commands will be executed with sudo privileges.
- Type:
bool
- su¶
If True, the commands will be executed with su privileges.
- Type:
bool
Examples:
# Ensure SELinux is set to enforcing mode r = yield LineInFile( path="/etc/selinux/config", regexp="^SELINUX=", line="SELINUX=enforcing" ) # Make sure group wheel is not in the sudoers configuration r = yield LineInFile( path="/etc/sudoers", state="absent", regexp="^%wheel" ) # Replace a localhost entry with our own r = yield LineInFile( path="/etc/hosts", regexp="^127\.0\.0\.1", line="127.0.0.1 localhost", owner="root", group="root", mode="0644" ) # Ensure the default Apache port is 8080 r = yield LineInFile( path="/etc/httpd/conf/httpd.conf", regexp="^Listen ", insertafter="^#Listen ", line="Listen 8080" )
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
This implementation mimics the behavior of Ansible’s lineinfile module.
Commands are constructed based on the provided parameters and flags.
Mutually exclusive parameters (backrefs/regxp/search_string, insertafter/insertbefore) are handled appropriately.
- class reemote.operations.builtin.get_url.GetUrl(url: str, dest: str, backup: bool = False, checksum: str = '', ciphers: list = None, client_cert: str = None, client_key: str = None, decompress: bool = True, force: bool = False, force_basic_auth: bool = False, group: str = None, headers: dict = None, http_agent: str = 'ansible-httpget', mode: str = None, owner: str = None, selevel: str = None, serole: str = None, setype: str = None, seuser: str = None, timeout: int = 10, tmp_dest: str = None, unredirected_headers: list = None, unsafe_writes: bool = False, url_password: str = None, url_username: str = None, use_gssapi: bool = False, use_netrc: bool = True, use_proxy: bool = True, validate_certs: bool = True, attributes: str = None, guard: bool = True)[source]¶
Bases:
objectA class to encapsulate the functionality of downloading files from HTTP, HTTPS, or FTP URLs. This mimics the behavior of Ansible’s ansible.builtin.get_url module.
- url¶
HTTP, HTTPS, or FTP URL in the form (http|https|ftp://[user[:pass]]@host.domain[:port]/path).
- Type:
str
- dest¶
Absolute path of where to download the file to.
- Type:
str
- backup¶
Create a backup file including the timestamp information.
- Type:
bool
- checksum¶
If a checksum is passed, the digest of the destination file will be calculated.
- Type:
str
- ciphers¶
SSL/TLS Ciphers to use for the request.
- Type:
list
- client_cert¶
PEM formatted certificate chain file for SSL client authentication.
- Type:
str
- client_key¶
PEM formatted file that contains your private key for SSL client authentication.
- Type:
str
- decompress¶
Whether to attempt to decompress gzip content-encoded responses.
- Type:
bool
- force¶
If true, will download the file every time and replace if contents change.
- Type:
bool
- force_basic_auth¶
Force the sending of the Basic authentication header.
- Type:
bool
- group¶
Name of the group that should own the filesystem object.
- Type:
str
- headers¶
Add custom HTTP headers to a request.
- Type:
dict
- http_agent¶
Header to identify as, generally appears in web server logs.
- Type:
str
- mode¶
The permissions the resulting filesystem object should have.
- Type:
str
- owner¶
Name of the user that should own the filesystem object.
- Type:
str
- selevel¶
The level part of the SELinux filesystem object context.
- Type:
str
- serole¶
The role part of the SELinux filesystem object context.
- Type:
str
- setype¶
The type part of the SELinux filesystem object context.
- Type:
str
- seuser¶
The user part of the SELinux filesystem object context.
- Type:
str
- timeout¶
Timeout in seconds for URL request.
- Type:
int
- tmp_dest¶
Absolute path of where temporary file is downloaded to.
- Type:
str
- unredirected_headers¶
Headers that will not be sent on subsequent redirected requests.
- Type:
list
- unsafe_writes¶
Influence when to use atomic operation to prevent data corruption.
- Type:
bool
- url_password¶
The password for use in HTTP basic authentication.
- Type:
str
- url_username¶
The username for use in HTTP basic authentication.
- Type:
str
- use_gssapi¶
Use GSSAPI to perform the authentication.
- Type:
bool
- use_netrc¶
Determining whether to use credentials from ~/.netrc file.
- Type:
bool
- use_proxy¶
If false, it will not use a proxy.
- Type:
bool
- validate_certs¶
If false, SSL certificates will not be validated.
- Type:
bool
- attributes¶
The attributes the resulting filesystem object should have.
- Type:
str
- guard¶
If False the commands will not be executed.
- Type:
bool
Examples:
# Download a file r = yield GetUrl(url="http://example.com/path/file.conf", dest="/etc/foo.conf") print(r.cp.stdout) # Download file with custom headers r = yield GetUrl( url="http://example.com/path/file.conf", dest="/etc/foo.conf", headers={"key1": "one", "key2": "two"} ) # Download file with checksum verification r = yield GetUrl( url="http://example.com/path/file.conf", dest="/etc/foo.conf", checksum="sha256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c" )
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
This implementation uses curl under the hood to perform the download.
Commands are constructed based on the provided parameters.
- class reemote.operations.builtin.apt_repository.AptRepository(repo: str, state: str = 'present', codename: str = None, filename: str = None, install_python_apt: bool = True, mode: str = None, update_cache: bool = True, update_cache_retries: int = 5, update_cache_retry_max_delay: int = 12, validate_certs: bool = True)[source]¶
Bases:
objectA class to manage APT repositories on Debian-based systems. This class allows adding or removing APT repositories similar to the ansible.builtin.apt_repository module.
- repo¶
A source string for the repository.
- Type:
str
- state¶
Desired state of the repository (‘present’ or ‘absent’).
- Type:
str
- codename¶
Override the distribution codename for PPA repositories.
- Type:
str
- filename¶
Sets the name of the source list file in sources.list.d.
- Type:
str
- install_python_apt¶
Whether to automatically install python3-apt.
- Type:
bool
- mode¶
The octal mode for newly created files in sources.list.d.
- Type:
str
- update_cache¶
Run apt-get update when a change occurs.
- Type:
bool
- update_cache_retries¶
Amount of retries if the cache update fails.
- Type:
int
- update_cache_retry_max_delay¶
Max delay for exponential backoff.
- Type:
int
- validate_certs¶
If false, SSL certificates will not be validated.
- Type:
bool
Examples:
# Add a repository r = yield AptRepository( repo="deb http://archive.canonical.com/ubuntu hardy partner", state="present" ) print(r.cp.stdout) # Remove a repository r = yield AptRepository( repo="deb http://archive.canonical.com/ubuntu hardy partner", state="absent" ) print(r.cp.stdout) # Add repository with custom filename r = yield AptRepository( repo="deb http://dl.google.com/linux/chrome/deb/ stable main", state="present", filename="google-chrome" ) print(r.cp.stdout)
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
Requires python3-apt and apt-key or gpg on the target system
Supports Debian Squeeze (version 6) and its successors
Works with both regular repositories and PPAs
- class reemote.operations.builtin.rpm_key.RpmKey(key: str, state: str = 'present', fingerprint: list = None, validate_certs: bool = True)[source]¶
Bases:
objectA class to manage GPG keys in the RPM database on RPM-based systems. This class provides functionality to add or remove GPG keys from the RPM database, supporting various key sources including URLs, local files, and existing key IDs.
- key¶
Key that will be modified. Can be a url, a file on the managed node, or a keyid if the key already exists in the database.
- Type:
str
- state¶
If the key will be imported or removed from the rpm db. Choices: “absent”, “present”.
- Type:
str
- fingerprint¶
The long-form fingerprint(s) of the key being imported for verification.
- Type:
list
- validate_certs¶
If false and the key is a url starting with https, SSL certificates will not be validated.
- Type:
bool
Examples:
# Import a key from a url r = yield RpmKey(state="present", key="http://apt.sw.be/RPM-GPG-KEY.dag.txt") # Import a key from a file r = yield RpmKey(state="present", key="/path/to/key.gpg") # Ensure a key is not present in the db r = yield RpmKey(state="absent", key="DEADB33F") # Verify the key, using a fingerprint, before import r = yield RpmKey(key="/path/to/RPM-GPG-KEY.dag.txt", fingerprint="EBC6 E12C 62B1 C734 026B 2122 A20E 5214 6B8D 79E6") # Verify the key, using multiple fingerprints, before import r = yield RpmKey(key="/path/to/RPM-GPG-KEY.dag.txt", fingerprint=["EBC6 E12C 62B1 C734 026B 2122 A20E 5214 6B8D 79E6", "19B7 913E 6284 8E3F 4D78 D6B4 ECD9 1AB2 2EB6 8D86"])
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
Commands are constructed based on the provided parameters and state.
Supports both adding (present) and removing (absent) keys from the RPM database.
Can verify keys using fingerprints before importing.
- class reemote.operations.builtin.yum_repository.YumRepository(name: str, state: str = 'present', description: str = None, baseurl: list = None, metalink: str = None, mirrorlist: str = None, file: str = None, enabled: bool = None, gpgcheck: bool = None, gpgkey: list = None, reposdir: str = '/etc/yum.repos.d', async_: bool = None, attributes: str = None, bandwidth: str = None, cost: str = None, countme: bool = None, deltarpm_metadata_percentage: str = None, deltarpm_percentage: str = None, enablegroups: bool = None, exclude: list = None, failovermethod: str = None, gpgcakey: str = None, group: str = None, http_caching: str = None, include: str = None, includepkgs: list = None, ip_resolve: str = None, keepalive: bool = None, keepcache: str = None, metadata_expire: str = None, metadata_expire_filter: str = None, mirrorlist_expire: str = None, mode: str = None, module_hotfixes: bool = None, owner: str = None, password: str = None, priority: str = None, protect: bool = None, proxy: str = None, proxy_password: str = None, proxy_username: str = None, repo_gpgcheck: bool = None, retries: str = None, s3_enabled: bool = None, selevel: str = None, serole: str = None, setype: str = None, seuser: str = None, skip_if_unavailable: bool = None, ssl_check_cert_permissions: bool = None, sslcacert: str = None, sslclientcert: str = None, sslclientkey: str = None, sslverify: bool = None, throttle: str = None, timeout: str = None, ui_repoid_vars: str = None, unsafe_writes: bool = False, username: str = None)[source]¶
Bases:
objectA class to encapsulate the functionality of managing YUM repositories in RPM-based Linux distributions. It allows users to add or remove YUM repositories with various configuration options.
- name¶
Unique repository ID. This option builds the section name of the repository in the repo file.
- Type:
str
- state¶
State of the repo file (‘present’ or ‘absent’).
- Type:
str
- description¶
A human-readable string describing the repository.
- Type:
str
- baseurl¶
URL(s) to the directory where the yum repository’s ‘repodata’ directory lives.
- Type:
list
- metalink¶
Specifies a URL to a metalink file for the repomd.xml.
- Type:
str
- mirrorlist¶
Specifies a URL to a file containing a list of baseurls.
- Type:
str
- file¶
File name without the .repo extension to save the repo in.
- Type:
str
- enabled¶
This tells yum whether or not use this repository.
- Type:
bool
- gpgcheck¶
Tells yum whether or not it should perform a GPG signature check on packages.
- Type:
bool
- gpgkey¶
URL(s) pointing to the ASCII-armored GPG key file for the repository.
- Type:
list
- reposdir¶
Directory where the .repo files will be stored.
- Type:
str
- async_¶
If set to true Yum will download packages and metadata from this repo in parallel.
- Type:
bool
- attributes¶
The attributes the resulting filesystem object should have.
- Type:
str
- bandwidth¶
Maximum available network bandwidth in bytes/second.
- Type:
str
- cost¶
Relative cost of accessing this repository.
- Type:
str
- countme¶
Whether a special flag should be added to a randomly chosen metalink/mirrorlist query.
- Type:
bool
- deltarpm_metadata_percentage¶
When the relative size of deltarpm metadata vs pkgs is larger than this.
- Type:
str
- deltarpm_percentage¶
When the relative size of delta vs pkg is larger than this.
- Type:
str
- enablegroups¶
Determines whether yum will allow the use of package groups for this repository.
- Type:
bool
- exclude¶
List of packages to exclude from updates or installs.
- Type:
list
- failovermethod¶
Method for failover (‘roundrobin’ or ‘priority’).
- Type:
str
- gpgcakey¶
A URL pointing to the ASCII-armored CA key file for the repository.
- Type:
str
- group¶
Name of the group that should own the filesystem object.
- Type:
str
- http_caching¶
Determines how upstream HTTP caches are instructed to handle HTTP downloads.
- Type:
str
- include¶
Include external configuration file.
- Type:
str
- includepkgs¶
List of packages you want to only use from a repository.
- Type:
list
- ip_resolve¶
Determines how yum resolves host names.
- Type:
str
- keepalive¶
This tells yum whether or not HTTP/1.1 keepalive should be used.
- Type:
bool
- keepcache¶
Determines whether or not yum keeps the cache of headers and packages.
- Type:
str
- metadata_expire¶
Time (in seconds) after which the metadata will expire.
- Type:
str
- metadata_expire_filter¶
Filter the metadata_expire time.
- Type:
str
- mirrorlist_expire¶
Time (in seconds) after which the mirrorlist locally cached will expire.
- Type:
str
- mode¶
The permissions the resulting filesystem object should have.
- Type:
str
- module_hotfixes¶
Disable module RPM filtering.
- Type:
bool
- owner¶
Name of the user that should own the filesystem object.
- Type:
str
- password¶
Password to use with the username for basic authentication.
- Type:
str
- priority¶
Enforce ordered protection of repositories.
- Type:
str
- protect¶
Protect packages from updates from other repositories.
- Type:
bool
- proxy¶
URL to the proxy server that yum should use.
- Type:
str
- proxy_password¶
Password for this proxy.
- Type:
str
- proxy_username¶
Username to use for proxy.
- Type:
str
- repo_gpgcheck¶
This tells yum whether or not it should perform a GPG signature check on the repodata.
- Type:
bool
- retries¶
Set the number of times any attempt to retrieve a file should retry.
- Type:
str
- s3_enabled¶
Enables support for S3 repositories.
- Type:
bool
- selevel¶
The level part of the SELinux filesystem object context.
- Type:
str
- serole¶
The role part of the SELinux filesystem object context.
- Type:
str
- setype¶
The type part of the SELinux filesystem object context.
- Type:
str
- seuser¶
The user part of the SELinux filesystem object context.
- Type:
str
If set to true yum will continue running if this repository cannot be contacted.
- Type:
bool
- ssl_check_cert_permissions¶
Whether yum should check the permissions on the paths for the certificates.
- Type:
bool
- sslcacert¶
Path to the directory containing the databases of the certificate authorities.
- Type:
str
- sslclientcert¶
Path to the SSL client certificate yum should use to connect to repos/remote sites.
- Type:
str
- sslclientkey¶
Path to the SSL client key yum should use to connect to repos/remote sites.
- Type:
str
- sslverify¶
Defines whether yum should verify SSL certificates/hosts at all.
- Type:
bool
- throttle¶
Enable bandwidth throttling for downloads.
- Type:
str
- timeout¶
Number of seconds to wait for a connection before timing out.
- Type:
str
- ui_repoid_vars¶
When a repository id is displayed, append these yum variables to the string.
- Type:
str
- unsafe_writes¶
Influence when to use atomic operation to prevent data corruption.
- Type:
bool
- username¶
Username to use for basic authentication to a repo.
- Type:
str
Examples:
# Add a repository r = yield YumRepository( name="epel", description="EPEL YUM repo", baseurl=["https://download.fedoraproject.org/pub/epel/$releasever/$basearch/"] ) print(r.repo) # Remove a repository r = yield YumRepository(name="epel", state="absent") print(r.state)
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
All comments will be removed if modifying an existing repo file.
Section order is preserved in an existing repo file.
Parameters in a section are ordered alphabetically in an existing repo file.
The repo file will be automatically deleted if it contains no repository.
- class reemote.operations.builtin.iptables.Iptables(action: str = 'append', chain: str = None, chain_management: bool = False, comment: str = None, ctstate: list = None, destination: str = None, destination_port: str = None, destination_ports: list = None, dst_range: str = None, flush: bool = False, fragment: str = None, gateway: str = None, gid_owner: str = None, goto: str = None, icmp_type: str = None, in_interface: str = None, ip_version: str = 'ipv4', jump: str = None, limit: str = None, limit_burst: str = None, log_level: str = None, log_prefix: str = None, match: list = None, match_set: str = None, match_set_flags: str = None, numeric: bool = False, out_interface: str = None, policy: str = None, protocol: str = None, reject_with: str = None, rule_num: str = None, set_counters: str = None, set_dscp_mark: str = None, set_dscp_mark_class: str = None, source: str = None, source_port: str = None, src_range: str = None, state: str = 'present', syn: str = 'ignore', table: str = 'filter', tcp_flags: dict = None, to_destination: str = None, to_ports: str = None, to_source: str = None, uid_owner: str = None, wait: str = None, guard: bool = True, sudo: bool = False)[source]¶
Bases:
objectA class to encapsulate the functionality of iptables rules management in Linux systems. This class allows users to add, remove, and manage iptables rules with various parameters similar to the ansible.builtin.iptables module.
- action¶
Whether the rule should be appended or inserted.
- Type:
str
- chain¶
Specify the iptables chain to modify.
- Type:
str
- chain_management¶
If true, create/delete chains as needed.
- Type:
bool
- comment¶
Comment to add to the rule.
- Type:
str
- ctstate¶
Connection states to match.
- Type:
list
- destination¶
Destination specification.
- Type:
str
- destination_port¶
Destination port or port range.
- Type:
str
- destination_ports¶
Multiple destination ports.
- Type:
list
- dst_range¶
Destination IP range.
- Type:
str
- flush¶
Flush all rules from chain/table.
- Type:
bool
- fragment¶
Fragment matching specification.
- Type:
str
- gateway¶
Gateway for TEE jump target.
- Type:
str
- gid_owner¶
Group ID for owner matching.
- Type:
str
- goto¶
Continue processing in specified chain.
- Type:
str
- icmp_type¶
ICMP type specification.
- Type:
str
- in_interface¶
Input interface specification.
- Type:
str
- ip_version¶
IP protocol version.
- Type:
str
- jump¶
Target of the rule.
- Type:
str
- limit¶
Rate limiting specification.
- Type:
str
- limit_burst¶
Burst limit specification.
- Type:
str
- log_level¶
Logging level for LOG jump.
- Type:
str
- log_prefix¶
Log prefix for LOG jump.
- Type:
str
- match¶
Extension modules for matching.
- Type:
list
- match_set¶
IP set name for matching.
- Type:
str
- match_set_flags¶
Flags for match_set parameter.
- Type:
str
- numeric¶
Skip DNS lookup in list operations.
- Type:
bool
- out_interface¶
Output interface specification.
- Type:
str
- policy¶
Chain policy setting.
- Type:
str
- protocol¶
Protocol specification.
- Type:
str
- reject_with¶
Error packet type for REJECT.
- Type:
str
- rule_num¶
Rule number for insertion.
- Type:
str
- set_counters¶
Initialize packet/byte counters.
- Type:
str
- set_dscp_mark¶
DSCP mark value.
- Type:
str
- set_dscp_mark_class¶
Predefined DiffServ class.
- Type:
str
- source¶
Source specification.
- Type:
str
- source_port¶
Source port or port range.
- Type:
str
- src_range¶
Source IP range.
- Type:
str
- state¶
Whether rule should be present or absent.
- Type:
str
- syn¶
SYN flag matching.
- Type:
str
- table¶
Packet matching table.
- Type:
str
- tcp_flags¶
TCP flags specification.
- Type:
dict
- to_destination¶
Destination for DNAT.
- Type:
str
- to_ports¶
Port redirection specification.
- Type:
str
- to_source¶
Source for SNAT.
- Type:
str
- uid_owner¶
User ID for owner matching.
- Type:
str
- wait¶
Wait time for xtables lock.
- Type:
str
- guard¶
If False, commands will not be executed.
- Type:
bool
- sudo¶
If True, execute with sudo privileges.
- Type:
bool
Examples:
# Block specific IP r = yield Iptables(chain="INPUT", source="8.8.8.8", jump="DROP", sudo=True) # Forward port 80 to 8600 r = yield Iptables( table="nat", chain="PREROUTING", in_interface="eth0", protocol="tcp", match=["tcp"], destination_port="80", jump="REDIRECT", to_ports="8600", comment="Redirect web traffic to port 8600", sudo=True ) # Allow related and established connections r = yield Iptables( chain="INPUT", ctstate=["ESTABLISHED", "RELATED"], jump="ACCEPT", sudo=True )
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
Commands are constructed based on the provided parameters
Supports both IPv4 and IPv6 through ip_version parameter
All parameters are optional except those required for specific operations
- class reemote.operations.builtin.async_status.AsyncStatus(jid: str, mode: str = 'status')[source]¶
Bases:
objectA class to encapsulate the functionality of the ansible.builtin.async_status module. This module gets the status of an asynchronous task and can also clean up the async job cache.
- jid¶
Job or task identifier (required).
- Type:
str
- mode¶
If “status”, obtain the status. If “cleanup”, clean up the async job cache. Defaults to “status”.
- Type:
str
Examples:
# Wait for asynchronous job to end r = yield AsyncStatus(jid=dnf_sleeper.ansible_job_id) # Check if job is finished if r.cp.finished: print("Job completed") # Clean up async file r = yield AsyncStatus(jid=dnf_sleeper.ansible_job_id, mode="cleanup")
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
The started and finished return values return True or False instead of 1 or 0.
This module is supported for both POSIX and Windows targets.
The module has a corresponding action plugin.
- class reemote.operations.builtin.systemd_service.SystemdService(name: str = None, state: str = None, enabled: bool = None, masked: bool = None, daemon_reload: bool = False, daemon_reexec: bool = False, force: bool = False, no_block: bool = False, scope: str = 'system', guard: bool = True)[source]¶
Bases:
objectA class to manage systemd units (services, timers, etc.) on remote hosts. This class provides functionality similar to Ansible’s systemd_service module, allowing control of systemd units through various operations like start, stop, restart, reload, enable, disable, mask, unmask, and daemon operations.
- name¶
Name of the unit. When no extension is given, it is implied to be .service.
- Type:
str
- state¶
Desired state of the unit (started, stopped, restarted, reloaded).
- Type:
str
- enabled¶
Whether the unit should start on boot.
- Type:
bool
- masked¶
Whether the unit should be masked (impossible to start).
- Type:
bool
- daemon_reload¶
Run daemon-reload before operations.
- Type:
bool
- daemon_reexec¶
Run daemon_reexec before operations.
- Type:
bool
- force¶
Override existing symlinks.
- Type:
bool
- no_block¶
Don’t wait for operation to finish.
- Type:
bool
- scope¶
Service manager scope (system, user, global).
- Type:
str
- guard¶
If False, commands will not be executed.
- Type:
bool
Examples:
# Start a service r = yield SystemdService(name="httpd", state="started") print(r.cp.stdout) # Stop a service r = yield SystemdService(name="cron", state="stopped") # Restart service with daemon reload r = yield SystemdService(name="crond", state="restarted", daemon_reload=True) # Enable a service r = yield SystemdService(name="httpd", enabled=True) # Mask a service r = yield SystemdService(name="unwanted-service", masked=True) # Force daemon reload r = yield SystemdService(daemon_reload=True)
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
At least one of state, enabled, or masked is required when specifying a name.
Operations are executed in order: enable/disable -> mask/unmask -> state management.
Commands are constructed based on the provided parameters and scope.
- class reemote.operations.builtin.fetch.Fetch(src: str, dest: str, fail_on_missing: bool = True, flat: bool = False, validate_checksum: bool = True, guard: bool = True)[source]¶
Bases:
objectA class to encapsulate the functionality of fetching files from remote nodes. This module works like copy, but in reverse. It is used for fetching files from remote machines and storing them locally in a file tree, organized by hostname.
Files that already exist at dest will be overwritten if they are different than the src. This module is also supported for Windows targets.
- src¶
The file on the remote system to fetch. This must be a file, not a directory.
- Type:
str
- dest¶
A directory to save the file into.
- Type:
str
- fail_on_missing¶
When set to true, the task will fail if the remote file cannot be read.
- Type:
bool
- flat¶
Allows you to override the default behavior of appending hostname/path/to/file to the destination.
- Type:
bool
- validate_checksum¶
Verify that the source and destination checksums match after the files are fetched.
- Type:
bool
- guard¶
If False the commands will not be executed.
- Type:
bool
Examples:
# Store file into /tmp/fetched/host.example.com/tmp/somefile r = yield Fetch(src="/tmp/somefile", dest="/tmp/fetched") # Specifying a path directly r = yield Fetch(src="/tmp/somefile", dest="/tmp/prefix-{}".format(inventory_hostname), flat=True) # Specifying a destination path r = yield Fetch(src="/tmp/uniquefile", dest="/tmp/special/", flat=True) # Storing in a path relative to the playbook r = yield Fetch(src="/tmp/uniquefile", dest="special/prefix-{}".format(inventory_hostname), flat=True)
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
When running fetch with become, the slurp module will also be used to fetch the contents of the file for determining the remote checksum. This effectively doubles the transfer size.
Files are organized by hostname in the destination directory unless flat=True is specified.
- class reemote.operations.builtin.blockinfile.BlockInFile(path: str, block: str = '', state: str = 'present', marker: str = '# {mark} ANSIBLE MANAGED BLOCK', marker_begin: str = 'BEGIN', marker_end: str = 'END', insertafter: str = None, insertbefore: str = None, create: bool = False, backup: bool = False, append_newline: bool = False, prepend_newline: bool = False, owner: str = None, group: str = None, mode: str = None, attributes: str = None, seuser: str = None, serole: str = None, setype: str = None, selevel: str = None, unsafe_writes: bool = False, validate: str = None, guard: bool = True)[source]¶
Bases:
objectA class to encapsulate the functionality of the ansible.builtin.blockinfile module. This module inserts, updates, or removes a block of multi-line text surrounded by marker lines in a file.
- path¶
The file to modify.
- Type:
str
- block¶
The text to insert inside the marker lines.
- Type:
str
- state¶
Whether the block should be there or not (“present” or “absent”).
- Type:
str
- marker¶
The marker line template.
- Type:
str
- marker_begin¶
Text inserted at {mark} in the opening marker.
- Type:
str
- marker_end¶
Text inserted at {mark} in the closing marker.
- Type:
str
- insertafter¶
Insert block after the last match of specified regex.
- Type:
str
- insertbefore¶
Insert block before the last match of specified regex.
- Type:
str
- create¶
Create a new file if it does not exist.
- Type:
bool
- backup¶
Create a backup file with timestamp information.
- Type:
bool
- append_newline¶
Append a blank line to the inserted block.
- Type:
bool
- prepend_newline¶
Prepend a blank line to the inserted block.
- Type:
bool
- owner¶
Name of the user that should own the file.
- Type:
str
- group¶
Name of the group that should own the file.
- Type:
str
- mode¶
The permissions the resulting file should have.
- Type:
str
- attributes¶
The attributes the resulting file should have.
- Type:
str
- seuser¶
The user part of the SELinux file context.
- Type:
str
- serole¶
The role part of the SELinux file context.
- Type:
str
- setype¶
The type part of the SELinux file context.
- Type:
str
- selevel¶
The level part of the SELinux file context.
- Type:
str
- unsafe_writes¶
Allow unsafe writes if atomic operations fail.
- Type:
bool
- validate¶
Validation command to run before copying the file.
- Type:
str
- guard¶
If False, the commands will not be executed.
- Type:
bool
Examples:
# Insert/Update "Match User" configuration block in /etc/ssh/sshd_config r = yield BlockInFile( path="/etc/ssh/sshd_config", block="Match User ansible-agent\nPasswordAuthentication no", append_newline=True, prepend_newline=True ) print(r.cp.stdout) # Insert/Update eth0 configuration in /etc/network/interfaces r = yield BlockInFile( path="/etc/network/interfaces", block="iface eth0 inet static\n address 192.0.2.23\n netmask 255.255.255.0" ) print(r.cp.stdout) # Remove HTML block and surrounding markers r = yield BlockInFile( path="/var/www/html/index.html", marker="<!-- {mark} ANSIBLE MANAGED BLOCK -->", block="", state="absent" ) print(r.cp.stdout)
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
When using loops, ensure each block has a unique marker to prevent overwriting.
The dest option from older versions is now path, but dest still works.
Multiple blocks in one file require different markers per task.
- class reemote.operations.builtin.copy.Copy(src: str = None, dest: str = None, content: str = None, backup: bool = False, force: bool = True, mode: str = None, owner: str = None, group: str = None, directory_mode: str = None, remote_src: bool = False, follow: bool = False, local_follow: bool = True, decrypt: bool = True, unsafe_writes: bool = False, validate: str = None, seuser: str = None, serole: str = None, setype: str = None, selevel: str = None, attributes: str = None, checksum: str = None, guard: bool = True, sudo: bool = False, su: bool = False)[source]¶
Bases:
objectA class to encapsulate the functionality of copying files to remote locations. It allows users to specify source and destination paths, along with various file system meta-information settings like permissions, ownership, and SELinux contexts.
- src¶
Local path to a file to copy to the remote server.
- Type:
str
- dest¶
Remote absolute path where the file should be copied to.
- Type:
str
- content¶
When used instead of src, sets the contents of a file directly.
- Type:
str
- backup¶
Create a backup file including timestamp information.
- Type:
bool
- force¶
Influence whether the remote file must always be replaced.
- Type:
bool
- mode¶
The permissions of the destination file or directory.
- Type:
str
- owner¶
Name of the user that should own the filesystem object.
- Type:
str
- group¶
Name of the group that should own the filesystem object.
- Type:
str
- directory_mode¶
Set access permissions of newly created directories.
- Type:
str
- remote_src¶
Influence whether src needs to be transferred or already present remotely.
- Type:
bool
- follow¶
Follow filesystem links in the destination.
- Type:
bool
- local_follow¶
Follow filesystem links in the source tree.
- Type:
bool
- decrypt¶
Control auto-decryption of source files using vault.
- Type:
bool
- unsafe_writes¶
Allow unsafe writes when atomic operations fail.
- Type:
bool
- validate¶
Validation command to run before copying the file.
- Type:
str
- seuser¶
SELinux user context.
- Type:
str
- serole¶
SELinux role context.
- Type:
str
- setype¶
SELinux type context.
- Type:
str
- selevel¶
SELinux level context.
- Type:
str
- attributes¶
File attributes to set on the resulting filesystem object.
- Type:
str
- checksum¶
SHA1 checksum of the file being transferred.
- Type:
str
- guard¶
If False the commands will not be executed.
- Type:
bool
- sudo¶
If True, the commands will be executed with sudo privileges.
- Type:
bool
- su¶
If True, the commands will be executed with su privileges.
- Type:
bool
Examples:
# Copy file with owner and permissions r = yield Copy(src="/srv/myfiles/foo.conf", dest="/etc/foo.conf", owner="foo", group="foo", mode="0644") print(r.cp.dest) # Copy using inline content r = yield Copy(content="# This file was moved to /etc/other.conf", dest="/etc/mine.conf") print(r.cp.dest) # Copy file with backup r = yield Copy(src="/mine/ntp.conf", dest="/etc/ntp.conf", owner="root", group="root", mode="0644", backup=True) print(r.cp.backup_file)
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
Commands are constructed based on the various parameters and flags.
For Windows targets, use the appropriate Windows copy module instead.
- class reemote.operations.builtin.apt_key.Apt_key(data: str = None, file: str = None, id: str = None, keyring: str = None, keyserver: str = None, state: str = 'present', url: str = None, validate_certs: bool = True, guard: bool = True, sudo: bool = True)[source]¶
Bases:
objectA class to encapsulate the functionality of managing apt keys in Debian-based systems. It allows users to add or remove apt keys from keyring, optionally downloading them from a keyserver or URL, or using local keyfiles.
- data¶
The keyfile contents to add to the keyring.
- Type:
str
- file¶
The path to a keyfile on the remote server to add to the keyring.
- Type:
str
- id¶
The identifier of the key.
- Type:
str
- keyring¶
The full path to specific keyring file in /etc/apt/trusted.gpg.d/.
- Type:
str
- keyserver¶
The keyserver to retrieve key from.
- Type:
str
- state¶
Ensures that the key is present (added) or absent (revoked).
- Type:
str
- url¶
The URL to retrieve key from.
- Type:
str
- validate_certs¶
If False, SSL certificates for the target url will not be validated.
- Type:
bool
Examples:
# Add an apt key by id from a keyserver r = yield AptKey(keyserver="keyserver.ubuntu.com", id="36A1D7869245C8950F966E92D8576A8BA88D21E9") # Add an Apt signing key from URL r = yield AptKey(url="https://ftp-master.debian.org/keys/archive-key-6.0.asc", state="present") # Remove an Apt specific signing key r = yield AptKey(id="0x9FED2BCBDCD29CDF762678CBAED4B06F473041FA", state="absent") # Add a key from data content key_data = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n..." r = yield AptKey(data=key_data, state="present") # Add an Apt signing key to a specific keyring file r = yield AptKey(id="9FED2BCBDCD29CDF762678CBAED4B06F473041FA", url="https://ftp-master.debian.org/keys/archive-key-6.0.asc", keyring="/etc/apt/trusted.gpg.d/debian.gpg")
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
The apt-key command used by this implementation has been deprecated.
Adding a new key requires an apt cache update.
Use full fingerprint (40 characters) key ids to avoid key collisions.
- class reemote.operations.builtin.service.Service(name: str, state: str = None, enabled: bool = None, pattern: str = None, arguments: str = '', runlevel: str = 'default', sleep: int = None, use: str = 'auto', guard: bool = True)[source]¶
Bases:
objectA class to manage services on remote hosts, similar to Ansible’s ansible.builtin.service module. This class allows users to control services by specifying the service name, desired state, whether it should be enabled at boot, and other service-specific options.
- name¶
Name of the service.
- Type:
str
- state¶
Desired state of the service (started, stopped, restarted, reloaded).
- Type:
str
- enabled¶
Whether the service should start on boot.
- Type:
bool
- pattern¶
Pattern to look for in ps output if service doesn’t respond to status.
- Type:
str
- arguments¶
Additional arguments provided on the command line.
- Type:
str
- runlevel¶
Runlevel for OpenRC init scripts (Gentoo).
- Type:
str
- sleep¶
Seconds to sleep between stop and start when restarting.
- Type:
int
- use¶
Force specific service module (systemd, sysvinit, etc.).
- Type:
str
- guard¶
If False, the commands will not be executed.
- Type:
bool
Examples:
# Start service httpd, if not started r = yield Service(name="httpd", state="started") print(r.cp.stdout) # Stop service httpd, if started r = yield Service(name="httpd", state="stopped") # Enable service httpd, and not touch the state r = yield Service(name="httpd", enabled=True) # Restart network service for interface eth0 r = yield Service(name="network", state="restarted", arguments="eth0")
- Usage:
This class is designed to be used in a generator-based workflow where commands are yielded for execution.
Notes
This implementation acts as a simplified proxy to underlying service managers.
Not all service managers support all options (e.g., systemd ignores arguments, pattern, runlevel).
For Windows targets, a different approach would be needed (not implemented here).
- class reemote.operations.builtin.debug.Debug(msg: str = 'Hello world!', var: str = None, verbosity: int = 0)[source]¶
Bases:
objectA class to encapsulate the functionality of the Ansible debug module. This module prints statements during execution and can be useful for debugging variables or expressions without necessarily halting the execution flow.
- msg¶
The customized message(s) that is printed. If omitted, prints a generic message.
- Type:
str or list
- var¶
A variable name to debug. Mutually exclusive with the msg option.
- Type:
str
- verbosity¶
A number that controls when the debug is run. Higher values require more verbose flags to display.
- Type:
int
Examples:
# Print a custom message yield Debug(msg="System has gateway") # Debug a variable yield Debug(var="result") # Print with specific verbosity level yield Debug(var="hostvars[inventory_hostname]", verbosity=4) # Print multiple messages yield Debug(msg=[ "Provisioning based on YOUR_KEY which is: {{ lookup('env', 'YOUR_KEY') }}", "These servers were built using the password of '{{ password_used }}'. Please retain this for later use." ])
- Usage:
This class is designed to be used in a generator-based workflow where debug statements are yielded for execution.
Notes
The var parameter is evaluated in Jinja2 context and has implicit {{ }} wrapping.
Verbosity controls when the debug output is shown based on the verbosity level specified during execution.