{"id":15013867,"url":"https://github.com/joknarf/deferlib","last_synced_at":"2025-10-09T11:31:05.763Z","repository":{"id":221833608,"uuid":"755504321","full_name":"joknarf/deferlib","owner":"joknarf","description":"puppet functions for deferred execution on agent side","archived":false,"fork":false,"pushed_at":"2024-02-13T22:50:02.000Z","size":117,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-28T17:16:39.185Z","etag":null,"topics":["agent","deferred","facts","library","puppet","puppet-module"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joknarf.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-10T12:17:04.000Z","updated_at":"2024-12-21T11:36:48.000Z","dependencies_parsed_at":"2024-02-10T13:29:49.501Z","dependency_job_id":"d6bb47e8-4d86-4f74-87bd-1a605c644ddc","html_url":"https://github.com/joknarf/deferlib","commit_stats":{"total_commits":48,"total_committers":2,"mean_commits":24.0,"dds":0.02083333333333337,"last_synced_commit":"7b802fad3676c662747db9b706cd3532b8b4859a"},"previous_names":["joknarf/deferlib"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joknarf%2Fdeferlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joknarf%2Fdeferlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joknarf%2Fdeferlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joknarf%2Fdeferlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joknarf","download_url":"https://codeload.github.com/joknarf/deferlib/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235815607,"owners_count":19049363,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent","deferred","facts","library","puppet","puppet-module"],"created_at":"2024-09-24T19:44:52.525Z","updated_at":"2025-10-09T11:31:05.330Z","avatar_url":"https://github.com/joknarf.png","language":"Ruby","readme":" [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n [![Puppet Forge](https://img.shields.io/puppetforge/v/joknarf/deferlib.svg)](https://forge.puppetlabs.com/joknarf/deferlib)\n[![Puppet Forge Downloads](https://img.shields.io/puppetforge/dt/joknarf/deferlib.svg)](https://forge.puppetlabs.com/joknarf/deferlib)\n\n# deferlib\n\n## Table of Contents\n\n1. [Description](#description)\n1. [Setup - The basics of getting started with deferlib](#setup)\n    * [Setup requirements](#setup-requirements)\n    * [Beginning with deferlib](#beginning-with-deferlib)\n1. [Usage](#usage)\n    * [deferlib::if_file()](#deferlibif_file)\n    * [deferlib::unless_file()](#deferlibunless_file)\n    * [deferlib::if_cmd()](#deferlibif_cmd)\n    * [deferlib::unless_cmd()](#deferlibunless_cmd)\n    * [deferlib::cmd()](#deferlibcmd)\n1. [Reference](REFERENCE.md)\n\n## Description\n\nControl your resources parameters from client side without creating useless facts.\n\nProvides functions library to use to get values for resource parameters\nfrom files/command executed on agent side (deferred), providing way to control resources\nfrom agent host local things without creating facts that executes on all servers.\n\n## Setup\n\n### Setup Requirements\n\nPuppet agent/server \u003e= 7\n\n### Beginning with deferlib\n\ndeferlib provides functions to use to modify resource parameters from host runnning\npuppet agent (instead of using facts for example).\n\nExample:\n```puppet\n# do not restart cron when maintenance flag file exists putting ensure to undef\n# =\u003e function to read: unless file /etc/maintenance exists ensure running, (else ensure undef)\nservice { 'cron':\n  ensure =\u003e deferlib::unless_file('/etc/maintenance', 'running'),\n}\n\n# noop mode when maintenance preventing starting service during operation\nservice { 'cron':\n  ensure =\u003e 'running',\n  noop   =\u003e deferlib::if_file('/etc/maintenance', true, false),\n}\n```\n\n## Usage\n\nfunctions available:\n\n### deferlib::if_file()\n```ruby\ndeferlib::if_file(file, value, [default])\n```\n#### Description:\nreturns `value` if `file` exists else returns `default` (default: [])\n\n#### Parameters:\n```\nfile    : path to file to check existence\nvalue   : value returned if file exists\ndefault : value returned if file does not exist (default [])\n```\n\n#### Example:\n```puppet\n# stop cron when cron_stop flag file exists\n# =\u003e function to read: if file /etc/cron_stop exists ensure stopped else ensure running\nservice { 'cron':\n  ensure =\u003e deferlib::if_file('/etc/cron_stop', 'stopped', 'running'),\n}\n```\n\n### deferlib::unless_file()\n```ruby\ndeferlib::unless_file(file, value, [default])\n```\n#### Description:\nreturns `value` if `file` does not exist else returns `default` (default: [])\n\n#### Parameters:\n```\nfile    : path to file to check existence\nvalue   : value returned if file does not exist\ndefault : value returned if file exists (default [])\n```\n\n#### Example:\n```puppet\n# do not restart cron when maintenance flag file exists putting ensure to undef ([])\n# =\u003e function to read: unless file /etc/maintenance exists ensure running, (else ensure undef)\nservice { 'cron':\n  ensure =\u003e deferlib::unless_file('/etc/maintenance', 'running'),\n}\n```\n\n### deferlib::if_cmd()\n```ruby\ndeferlib::if_cmd(cmd, value, [options])\n```\n#### Description:\nreturns `value` if exit code of `cmd` is 0 else returns `options[else]` (default to [])\n\n#### Parameters:\n```\ncmd     : shell code to execute\nvalue   : value returned if exit status is 0\noptions : {\n  'else'        =\u003e # value returned if exit status is not 0 (default: [])\n  'user'        =\u003e # The user to run the command as\t\n  'group'       =\u003e # The group to run the command as\n  'environment' =\u003e # A Hash of environment variables\n}\noptions['environment'] : {\n  '\u003cvariable name\u003e' =\u003e # value of the environement variable\n  ...\n}\n```\n\n#### Example:\n```puppet\n# ensure cron running if isproduction returns 0\nservice { 'cron':\n  ensure =\u003e deferlib::if_cmd('/bin/isproduction', 'running', {\n          'user'    =\u003e 'foo',\n          'group'   =\u003e 'bar',\n  }),\n}\n```\n\n### deferlib::unless_cmd()\n```ruby\ndeferlib::unless_cmd(cmd, value, [options])\n```\n#### Description:\nreturns `value` if exit code of `cmd` is not 0 else returns `options[else]` (default to [])\n\n#### Parameters:\n```\ncmd     : shell code to execute\nvalue   : value returned if exit status is not 0\noptions : Hash with optional settings\noptions : {\n  'else'        =\u003e # value returned if exit status is 0 (default: [])\n  'user'        =\u003e # The user to run the command as\t\n  'group'       =\u003e # The group to run the command as\n  'environment' =\u003e # A Hash of environment variables\n}\noptions['environment'] : {\n  '\u003cvariable name\u003e' =\u003e # value of the environement variable\n  ...\n}\n```\n\n#### Example:\n```puppet\n# ensure cron running unless ismaintenance returns 0\nservice { 'cron':\n  ensure =\u003e deferlib::unless_cmd('/bin/ismaintenance', 'running', {\n          'user'    =\u003e 'foo',\n          'group'   =\u003e 'bar',\n  }),\n}\n```\n\n### deferlib::cmd()\n```ruby\ndeferlib::cmd(options)\n```\n#### Description:\nreturns output of `options[command]` if exit code is 0 else returns `options['else']` (default to [])\n\n#### parameters:\n```\noptions : Hash with parameters\noptions : {\n  'command'     =\u003e # Shell code to execute\n  'match'       =\u003e # regexp to validate output (returns options['else'] if not)\n  'else'        =\u003e # value returned if exit code is not 0\n  'user'        =\u003e # The user to run the command as\t\n  'group'       =\u003e # The group to run the command as\n  'environment' =\u003e # A Hash of environment variables/values\n}\noptions['environment'] : {\n  '\u003cvariable name\u003e' =\u003e # value of the environement variable\n  ...\n}\n```\n\n#### Example:\n```puppet\n# force ensure from local file content if exists, else ensure running\nservice { 'cron':\n  ensure =\u003e deferlib::cmd({\n          'command' =\u003e 'cat /etc/cron_ensure',\n          'else'    =\u003e 'running',\n  }),\n}\n# use script cron_ensure from puppet module files\nservice { 'cron':\n  ensure =\u003e deferlib::cmd({\n          'command' =\u003e file(\"${module_name}/cron_ensure\"),\n  }),  \n}\n```\n## Reference\n\n[Reference](REFERENCE.md)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoknarf%2Fdeferlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoknarf%2Fdeferlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoknarf%2Fdeferlib/lists"}