
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
@johnls/octopus
Advanced tools
Octopus is a system for performing IT automation. It's written in Javascript using Node.js. Script files are created in JSON5 format and consist of a sequence of assertions that ensure the state of target system. Scripts are idempotent in that after one run of a script to set things into a desired state, subsequent runs of the same script result in no changes to the target.
Install the package globally:
npm install -g @johnls/octopus
octopus --help
Or use npx
to run the latest version:
npx @johnls/octopus --help
Here is a valid Octopus script that creates some directories and files on a remote system:
{
// Global settings for the script go here
settings: {
description: "A basic script",
},
// Global variables go here
vars: {
testDir1: "octo-dir-1",
testFile1: "octo-file-1",
},
// Every script must have a list of assertions
assertions: [
{
description: "Ensure a test directory",
// Each assertion specifies an asserter
assert: "DirectoryExists",
// And arguments
with: {
// Arguments can include Javascript
path: "{var.testDir1}",
},
},
{
assert: "FileExists",
with: {
path: "{path.join(var.testDir1, var.testFile1)}",
},
},
],
}
Octopus has the following key features:
Not surprisingly, Octopus borrows from the design of Ansible. It uses SSH to avoid having remote agents. Ansible's plays are similar to Octopuses asserters.
The design goals of Octopus are:
Octopus scripts are made up of:
Scripts are a sequence of assertions executed sequentially. The order of the assertions is important. Later assertions can expect the assertions higher up in the script to have either be true or to have been rectified to be true. Note that it is fine to write a script where all the assertions are not expected to be true each time the script is run. For example, you might write a script to stop a service so you can set some configuration files, then start the service again. The stop/start assertions will always be triggered. The important thing is that assertions ensure that the script doesn't make changes it doesn't have too. This is really helpful when restarting a script after an unexpected failure, for example.
Assertions are a collections of assertions about a host state. Assertions are run one at a time, from the top of the script to bottom. Each assertion makes a statement about some particular type of the host machine state. If that state is not true, then the asserter tries to rectify the situation and make that assertion true. There are asserters for files, directories, users, groups, file downsloads, file contents, and so on.
See the full list of built-in asserters in the documentation directory.
Octopus uses SSH to run scripts on remote hosts. When run against one or more hosts, Octopus uses SSH to run scripts on those hostes. When run without a remote host, Octopus just runs the script directly on your local system.
Octopus uses an enhanced fork of the JSON5 library that returns Node
objects instead of simple Javascript values for each value, array or object in the JSON5. A node object has type
and value
fields, plus line
and column
fields showing where in the JSON5 file the node comes from. This allows error messages that contain location information to help the Octopus user to find and fix errors in their script.
The asserter must be a Javascript class. The constructor
will be called with a container
object, which at a minimum contains:
Each script assertions runs with a new instance of the specified asserter. assert
will always be called. rectify
will only be called if the assertion condition has not been met.
{
// Expand a string by treating it as a Javascript template and running it in a VM
interpolator: (string) => {...},
// The assertion node in the JSON5
assertNode: {...},
}
The constructor
should:
container
object references to this
.container
. In this way mock modules can be injected for testing. See existing asserters for examples of making asserters testable.The goals for the assert
method are:
this.util.osInfo()
. Throw ScriptError
on the assertNode
if not.assertNode
in the assertNode.value.with
node. Throw a ScriptError
if the arguments are invalid passing the error message and the node causing the error.this.interpolator()
on any with
arguments that can be expanded.rectify
in this
, including the passed in assertNode
.ScriptError
on the assertNode
. If the condition has already been met, return true
.false
if the assertion condition can be met but has not been yet.The method rectify()
is called to modify the host state:
assert
checks for will succeed next time.ScriptError
on this.assertNode
if the condition cannot be satisfied.this
from the assert
method.Finally, the result()
method will always be called to output the result of the asserter, with a rectified
flag:
throw
from this methodAsserter class naming should generally follow these conventions:
Asserter argument naming should generally follow these conventions:
user
, directory
, file
, group
, etc..fromFile
and toFile
FAQs
Simple, agentless IT automation
The npm package @johnls/octopus receives a total of 0 weekly downloads. As such, @johnls/octopus popularity was classified as not popular.
We found that @johnls/octopus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.