{"id":22913779,"url":"https://github.com/re-ops/re-cog","last_synced_at":"2025-05-12T13:29:52.970Z","repository":{"id":44342865,"uuid":"190022371","full_name":"re-ops/re-cog","owner":"re-ops","description":"A set of remotely exeutable functions","archived":false,"fork":false,"pushed_at":"2024-10-30T09:01:59.000Z","size":462,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T22:34:54.291Z","etag":null,"topics":["clojure","configuration","function","management","provision","re-mote","re-ops","remote"],"latest_commit_sha":null,"homepage":"","language":"Clojure","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/re-ops.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-2.0.txt","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":"2019-06-03T14:31:44.000Z","updated_at":"2024-10-30T09:02:02.000Z","dependencies_parsed_at":"2024-12-14T05:22:03.201Z","dependency_job_id":null,"html_url":"https://github.com/re-ops/re-cog","commit_stats":{"total_commits":392,"total_committers":2,"mean_commits":196.0,"dds":"0.022959183673469385","last_synced_commit":"025b26e9e3911e34a16ae91c739c74342d91f5c1"},"previous_names":[],"tags_count":60,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/re-ops%2Fre-cog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/re-ops%2Fre-cog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/re-ops%2Fre-cog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/re-ops%2Fre-cog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/re-ops","download_url":"https://codeload.github.com/re-ops/re-cog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253747521,"owners_count":21957773,"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":["clojure","configuration","function","management","provision","re-mote","re-ops","remote"],"created_at":"2024-12-14T05:11:57.412Z","updated_at":"2025-05-12T13:29:52.921Z","avatar_url":"https://github.com/re-ops.png","language":"Clojure","readme":"# Intro\n\nRe-cog is a set of serializable functions that can be executed by [Re-gent](https://github.com/re-ops/re-gent).\n\nThe functions are divided into a number categories:\n\n* Resources which are used in provisioning recipes to setup remote machines (see [Re-cipes](https://github.com/re-ops/re-cipes)).\n* Facts which are use to get information from remote machines including security audit, performance metrics.\n* Common shell scripts that we can execute remotely.\n\nWe can change the functions on the fly by refreshing the REPL and run the latest version on our remote hosts (no restart required!) using the [Reloaded](https://re-ops.github.io/re-docs/usage/#reloaded) workflow.\n\nRe-cog resources facts and scripts have a number of use cases:\n\n* To be used within provisioning [recipes](https://github.com/re-ops/re-cipes).\n* To be used in Re-mote [pipelines](https://re-ops.github.io/re-docs/#abstractions).\n* To be directly invoked on a cluster of machines for ad-hoc execution.\n\nIt is a part of the [Re-ops](https://re-ops.github.io/re-ops/) project that offers a live coding environment for managing and information gathering from remote systems.\n\n[![Build Status](https://travis-ci.org/re-ops/re-cog.png)](https://travis-ci.org/re-ops/re-cog)\n\n# Usage\n\n### Provisioning Recipes\n\nA recipe is a Clojure namespace which includes a list of functions used to provision a component in a system, each one of those functions use resources/facts and is serializable by using [def-inline](https://github.com/re-ops/re-cog/blob/master/src/re_cog/common/defs.clj#L73).\n\nIn the following example we setup a ZSH shell, we start by requiring our Re-cog resources/facts and adding def-inline by using the require-recipe macro:\n\n```clojure\n(ns re-cipes.shell\n  \"Setting up shell\"\n  (:require\n   [re-cog.resources.git :refer (clone)]\n   [re-cog.resources.exec :refer [run]]\n   [re-cog.common.recipe :refer (require-recipe)]\n   [re-cog.facts.config :refer (configuration)]\n   [re-cog.resources.download :refer (download)]\n   [re-cog.resources.file :refer (symlink directory chmod)]))\n\n(require-recipe)\n```\nThe recipe functions use [resources](https://github.com/re-ops/re-cog/tree/master/src/re_cog/resources) (clone,chown etc..) and [facts](https://github.com/re-ops/re-cog/tree/master/src/re_cog/facts) (configuration) to provision the machine, each of the functions is responsible to a single component of our recipe:\n\n```clojure\n(def-inline zsh\n  \"zsh setup\"\n  []\n  (letfn [(chsh [user]\n            (fn []\n              (script (\"sudo\" \"/usr/bin/chsh\" \"-s\" \"/usr/bin/zsh\" ~user))))]\n    (let [{:keys [home user]} (configuration)\n          dest (\u003c\u003c \"~{home}/.tmux\")]\n      (package \"zsh\" :present)\n      (when-not  (clojure.string/includes? (\u003c\u003c \"~{user}:/bin/zsh\") (slurp \"/etc/passwd\"))\n        (run (chsh user))))))\n\n(def-inline minimal-zsh\n  \"Minmal zsh setup\"\n  []\n  (let [{:keys [home user]} (configuration)\n        dest (\u003c\u003c \"~{home}/.minimal-zsh\")]\n    (clone \"git://github.com/narkisr/minimal-zsh.git\" dest)\n    (chown dest user user {})\n    (symlink (\u003c\u003c \"~{home}/.zshrc\") (\u003c\u003c \"~{dest}/.zshrc\"))))\n```\n\n### Re-mote pipelines\n\nRe-mote pipeline are using Re-cog scripts/facts/resources:\n\n```clojure\n(defn ^{:category :stats} cpu-persist\n  \"Collect CPU and idle usage with persistence (metrics collection):\n     (cpu-persist hs)\n  \"\n  [hs]\n  (run\u003e (cpu hs) | (enrich \"cpu\") | (persist) | (riemann)))\n```\n\nThe pipeline uses the [cpu](https://github.com/re-ops/re-core/blob/master/src/re_mote/zero/stats.clj#L116) function that extends hosts, here we use both the shell resource function and cpu-script:\n\n```clojure\n(extend-type Hosts\n  Stats\n  ...\n  (cpu\n    ([this]\n     (into-dec (zip this (run-hosts this shell (shell-args cpu-script) timeout) :stats :cpu :usr :sys :idle)))\n    ([this _]\n     (cpu this)))\n  ...\n)\n\n```\n### Adhoc invocation\n\nIn some cases it is useful to invoke Re-cog functions in an adhoc manner (for interactive data collection or during development):\n\n```clojure\n; collecting the cpu vulnerabilities from our hosts\n(run-hosts (hosts ip :hostname) re-cog.facts.security/cpu-vulns [] [10 :second])\n```\n\n# Copyright and license\n\nCopyright [2020] [Ronen Narkis]\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n  [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fre-ops%2Fre-cog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fre-ops%2Fre-cog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fre-ops%2Fre-cog/lists"}