Gardience Documentation gardience.com →
Docs / Using Gardience

Ansible playbooks

Gardience runs existing Ansible playbooks over the Salt connection it already has to every node. You do not need WinRM on Windows nodes, SSH keys for Linux nodes, or an inventory file.

Start here: Automation > Ansible

#

Automation > Ansible is the home for everything Ansible. It has four tabs and a search box:

People who are not admins can run playbooks there. An admin makes them runnable. Coming from AWX or Ansible Automation Platform? The table at the bottom of the page shows where each AWX feature lives in Gardience.

Write a playbook

#

Choose Create playbook. Start from an example (install a package, restart a service, put a setting in a config file, run a command, install Windows updates, turn on a Windows feature) or paste your own.

Try it on one machine

#

After saving, Try it on this machine runs the playbook in check mode on one machine that is on now, and says what happened in words for each task: what would change ("would install tree"), what is already as wanted ("already installed: htop"), or why it would fail. Nothing is changed. A task marked check_mode: false runs for real even in a preview, and the editor warns about it. Run on group runs it for real on the whole group, through the usual permissions, change windows, and approvals.

On Debian and Ubuntu, a preview of a package step needs the python3-apt package. When a machine does not have it, the result says so and offers Install python3-apt on machine , then preview again.

become

#

become: true works on every Linux machine, including ones without sudo: the Gardience agent already runs as root, so becoming root needs nothing, and becoming another user uses runuser. Playbooks written for SSH work unchanged.

What each run reports

#

Every Ansible run's log has one line for each task on each machine: what changed (for packages, the names installed or removed), what was already as wanted, or why it failed. Commands show their first lines of output, file changes their path.

There are two ways to run a playbook:

ModeRunbookNodesWhere ansible-playbook runs
Controller modeRun an Ansible playbook (Windows and Linux, no WinRM)Windows and LinuxOn the Gardience server, in the separate playbook runner
Local modeRun an Ansible playbook (Linux)Linux onlyOn each node, against itself

Uploads from the gdn command line use controller mode.

Controller mode

#

How it works

#
  1. Gardience builds the inventory from the target nodes. Windows nodes use PowerShell. Linux nodes use their own Python.
  2. The playbook runs in the playbook runner, a separate container that holds no Gardience data or secrets. Each run gets its own unprivileged account and private folder, and anything the run leaves behind is removed when it ends.
  3. Each command a task sends to a node goes as a Salt job to that node only. The command and its result are encrypted with that node's own key, so Salt's job history only ever holds encrypted data.
  4. The run can reach only the nodes it was approved for, and only for the length of the run (at most 4 hours).

One step of a playbook may run for up to an hour, for example a large Windows update. To change that for one playbook, set the variable gardience_salt_timeout (in seconds). If a command's message to a node or the node's answer is lost on the way, Gardience notices within about a minute and sends the command again. The node never runs the same command twice: it returns the saved result instead.

If a command gets no answer, Gardience sends it again. Each command carries an ID, so a node that already ran it returns the saved result instead of running it twice.

Who can run it

#

Running a playbook means running commands on the nodes. The person behind the run needs command-execution rights (cmd.run_all) on every target node, or the run is refused.

Controller runs go through the same checks as any runbook:

Run a playbook

#

Playbook runs run commands on machines, so command execution must be on for Gardience's automation. If a run is refused for that, root on the server turns it on with gardience automation commands on.

  1. Open Automation > Runbooks.
  2. On Run an Ansible playbook (Windows and Linux, no WinRM), choose Run….
  3. Fill in the form:

    • Node group: the nodes to run on.
    • Project: the demo project that ships with the server, or one of your Git projects.
    • Playbook (path in the project): for example site.yml or playbooks/web.yml.
    • Limit to machines: optional. Machine names or wildcards separated by commas, with ! to leave one out, for example web-*,!web-03. The limit only narrows the node group, and approvals, locks and the audit log see the narrowed list.
    • Only these tags: optional. Ansible tags separated by commas, like --tags.
    • Extra variables: optional. name=value pairs separated by spaces, like -e. Names starting with ansible_ or gardience_ are refused, so a run can never leave the Salt connection.
    • Vault secrets to pass: secret names, separated by commas. Leave empty for none.
    • Check mode (preview only): True runs Ansible with --check --diff, which shows what would change without changing it.
  4. Choose Run now as your name.

The run log shows each node's result with Ansible's own ok, changed and failed counts, followed by a PLAY RECAP. If ansible-playbook cannot start (for example, because of a YAML error), the log shows its error message.

Git projects

#

Keep your playbooks in Git, the way you did with AWX or Ansible Automation Platform, and run them from Gardience.

Add a project

#
  1. Choose how Gardience reaches the repository:

    • https with a token: store an access token in the Secrets vault first, either the token alone or user:token. GitHub, GitLab, Bitbucket, Azure DevOps and Gitea tokens all work. A public repository needs no token.
    • SSH with a deploy key: use an SSH address such as git@github.com:acme/infra.git or ssh://git@git.example.com:2222/srv/git/infra.git. Gardience creates a key pair for the project and shows its public key on the Projects page. Add it to the repository as a read-only deploy key (GitHub: Settings, Deploy keys; GitLab: Settings, Repository, Deploy keys; Bitbucket: Repository settings, Access keys), then choose Sync now. The private key is sealed with the server's vault key and never shown.
  2. Open Automation > Projects.
  3. Under Add a Git project, fill in:

    • Name: lowercase letters, digits, - and _, up to 40 characters.
    • Clone address: the https address, with no user name or token in it.
    • Branch or tag: main unless you say otherwise.
    • Token from the vault: the secret name from step 1. Leave empty for a public repository.
    • Pin to commit: optional. A full 40-character commit id. The project then stays on exactly that commit until you change or clear it.
    • Sync on a timer: every hour, every 6 hours, or every day. Off by default (sync by hand, by webhook, or before a run). A sync that fails waits for the next turn.
    • Update before every run: Gardience syncs the branch before each run of a playbook from this project.
    • Allow choosing a branch, tag or commit at run time: see below.
  4. Choose Save. An https project syncs right away; an SSH project syncs once you have added its deploy key.

Only admins add, sync and delete projects. A sync:

Every run from a Git project logs the project, the commit and the time of the sync.

Your Git projects at the top of the page lists every project with what it follows, its status, its commit and how many playbooks it has. Under each project, Sync history keeps its last 20 syncs: when, who or what started it (a person, the push webhook, the timer, or a run), whether it worked, the commit it moved from and to (or "no new commits"), how long it took, and the install log. Tokens are removed from the log.

Python packages

#

Some collections need Python packages on the controller, for example VMware or cloud collections. List them in a requirements.txt at the top of the project (one package per line, with an optional version, such as pyvmomi>=8.0). Gardience also reads the requirements.txt of each collection the project installs. At sync, Gardience installs them into the project:

Playbooks from the project then find the packages when they run. This is what AAP's execution environments are for, without building container images.

Collections source

#

By default, collections come from Ansible Galaxy and Python packages from PyPI. On a private or air-gapped network, set Collections source on the Projects page to your own Galaxy server (Automation Hub, Galaxy NG or Pulp) and your own Python package index (Artifactory, Nexus or devpi). Every collection and package Gardience downloads is also kept in a mirror on the server, so a later sync still installs it when the Galaxy server cannot be reached. The playbook runner itself never needs the internet: collections and roles travel with the project.

Sync on every push

#

Each project has a push webhook. On the Projects page, open Push webhook under the project for the payload address and secret.

Git hostWhere the secret goes
GitHub, Gitea, ForgejoThe webhook's secret (Gardience checks the signature)
GitLabThe webhook's secret token
Anything elseAn X-Gardience-Token header

A push to another branch is ignored. A webhook with the wrong secret gets HTTP 403 and changes nothing.

Signed commits only

#

To make sure only code from your own developers runs, edit the project, tick Only run commits signed by an approved developer, and paste each developer's SSH public key, one per line, as GitHub shows it (ssh-ed25519 AAAA... ann@acme.com). From then on every sync, manual, by webhook, on the timer, before a run or for a branch chosen at run time, checks the commit it lands on:

So a stolen Git password, or a push by someone with access to the repository but not on your list, never reaches a machine. Developers sign with the SSH key they already use:

git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub
git config --global commit.gpgsign true

GitHub, GitLab and Bitbucket then mark their commits Verified once the same key is added there as a signing key. SSH signatures are checked; GPG signatures are not yet.

Choose a branch at run time

#

When a project allows it, a run can use another branch, tag or commit than the project's own, for example to try a feature branch before it is merged (AWX calls this branch override). The built-in controller runbook and runbooks made from that project's playbooks then show Branch, tag or commit. Gardience fetches that branch for the run only, logs its commit, and keeps the five most recently used branches cached. A project that does not allow it refuses such a run.

A branch that is not merged yet may hold code nobody has reviewed. Allow this only on projects where that is acceptable, and keep change windows and approvals on production groups.

Turn a playbook into a runbook

#

On the Projects page, each playbook has Make a runbook. Gardience reads the playbook and builds a form:

People who may run runbooks then run the playbook from that form, without writing YAML or knowing Ansible. Form values may only use letters, digits, spaces and . , : @ / + = _ -, so a value can never carry Ansible template code.

Inventory sources

#

An inventory source is what AWX and Ansible Automation Platform call an inventory source: a dynamic inventory that Gardience syncs on a schedule or when you ask. Each sync runs ansible-inventory --list in the playbook runner, then:

Open Automation > Ansible > Inventory sources. Each source shows its last sync, how many of its hosts match a machine, and the next step (for example "2 hosts are not enrolled"). Sync now syncs it at once; the name opens its details: Matched, Not enrolled, Gone from the source, Groups, and Sync history. Admins add, change, sync, and delete sources.

Add a source

#
  1. Put the credential in the Secrets vault first, and tick Gardience only so no machine receives it. Inventory sources accept only Gardience-only secrets, and the vCenter, NetBox, and ServiceNow addresses must not be this server, loopback, or a cloud metadata address. For Amazon EC2, that is an access key ID and a secret access key of an IAM user with read-only EC2 access (ec2:DescribeInstances and ec2:DescribeRegions are enough).
  2. Choose Add source and fill in:

    • Name and Short name. The short name is the start of every group the source makes.
    • Inventory from:

      • A plugin config: the YAML you would put in AWX's source variables, with its plugin: line. Start from fills in a working config for Amazon EC2 (amazon.aws.aws_ec2), Microsoft Azure (azure.azcollection.azure_rm), VMware vCenter (vmware.vmware.vms; community.vmware.vmware_vm_inventory also works), Google Cloud (google.cloud.gcp_compute), NetBox (netbox.netbox.nb_inventory), and ServiceNow (servicenow.itsm.now). Use keyed_groups, groups, compose, filters, and hostnames as you would in AWX. A secret written into the config is refused: the config is shown to every admin, so secrets go under Credential.
      • An inventory script: a script that prints the inventory as JSON for --list, starting with #!.
      • A file or folder in a project: an INI or YAML inventory, a folder with group_vars and host_vars, or a plugin config, from a Git or local project. The project is synced first when it updates on launch, and the project's own collections (its requirements.yml) are used. Scripts inside a project folder are not run; add a script as An inventory script instead.
    • Credential: the type (Amazon Web Services, Microsoft Azure, VMware vCenter, Google Cloud, NetBox, or ServiceNow) and the vault secret for each value. Gardience hands them to the plugin the way AWX does, as the environment variables the plugin reads (AWS_ACCESS_KEY_ID, AZURE_SECRET, VMWARE_PASSWORD, NETBOX_TOKEN, and so on), for that one sync only. Choose None when the config needs no secret or the Gardience server's own cloud role is used.
    • Group prefix (the short name and a dot unless you change it) and Groups to keep (wildcards; ! leaves one out, for example tag_*, !tag_Name_*).
    • Sync: only when you press Sync now, or every 15 minutes, hour, 6 hours, or day.
    • New hosts in the source: see Enroll hosts from a source.
  3. Choose Save and sync.

An Amazon EC2 config that names hosts by their Name tag and makes AWX's tag_KEY_VALUE groups:

plugin: amazon.aws.aws_ec2
regions:
  - us-east-1
hostnames:
  - tag:Name
  - private-dns-name
keyed_groups:
  - key: tags          # tag_Role_web, tag_Env_prod
    prefix: tag
compose:
  ec2_region: placement.region

Groups

#

Every group in the inventory (all and ungrouped aside) becomes a Gardience node group named with the prefix, for example aws-prod.tag_Role_web. A group holds the matched machines of its hosts and of its child groups, as in Ansible. aws-prod.all holds every matched machine of the source, a handy default for its runbooks. The groups work everywhere a node group does: runbooks, workflows, schedules, change windows, and the vault.

How hosts are matched

#

A host in the source matches an enrolled machine when exactly one machine fits it, checked in this order:

  1. A match from an earlier sync, or a host Gardience enrolled from this source.
  2. The machine's name equals the host's name or one of its DNS names.
  3. The machine's cloud instance ID, system UUID, or serial number equals the host's (instance_id for EC2, the VM's UUID for VMware and Azure, the instance ID for Google Cloud).
  4. The machine's DNS name equals one of the host's, then its short name, when only one machine has that short name.
  5. One of the machine's IP addresses equals one of the host's (private or public IP, ansible_host).

A host that fits two machines, or a machine that fits two hosts, at the same step is not matched; Not enrolled says why. The machine's name is checked by Salt against its key. Instance IDs, DNS names, and addresses are things a machine reports about itself, so a match, once made, holds: another machine that later reports the same address does not take over the host, its groups, or its variables. A machine whose host left the source (a terminated instance) is not matched to a new host by a reused IP address.

Enroll hosts from a source

#

Not enrolled lists the hosts in the source with no machine. Pick hosts and choose Enroll selected. Gardience installs the agent through the same enrollment playbook as Add machines over SSH, with the credentials named under How Gardience reaches new hosts to enroll them (under Edit, the New hosts part of the form). Ask an admin to approve each new host and Enroll them automatically need these credentials before the source can be saved:

New machines join with a short-lived enrollment and match their host on their own once they join.

New hosts in the source decides what happens to a host that appears after the first sync:

The first sync of a source lists every host but enrolls none, whatever the setting. Every enrollment is in the audit log (inventory.enroll, then enroll.inventory_source with the result).

Gone from the source

#

A machine whose host has left the source (a terminated instance, a deleted VM, a server retired in the CMDB) is listed under Gone from the source with the date it left. Gardience never removes a machine for this: remove it from its page when you are sure, or it comes back to the matched list if the host returns.

Host variables and groups in playbooks

#

When a playbook runs through Gardience, each targeted machine that matched a host gets that host's variables and groups, exactly as ansible-inventory --list returned them:

- hosts: tag_Role_web
  tasks:
    - ansible.builtin.debug:
        msg: "{{ inventory_hostname }} runs in {{ ec2_region }}, private IP {{ private_ip_address }}"

Collections that ship with Gardience

#

The playbook runner image includes these collections and the libraries their inventory plugins need, so syncs work on air-gapped servers too: amazon.aws (with boto3), azure.azcollection (with the Azure identity libraries), community.vmware and vmware.vmware (with pyVmomi), google.cloud (with google-auth), netbox.netbox, and servicenow.itsm, plus pywinrm for Windows enrollment. Together they add about 100 MB to the image. For any other plugin, add its collection to a project's requirements.yml (and Python packages to its requirements.txt) and use A file or folder in a project: the project's own collections come first.

Security

#

Import from AWX or Ansible Automation Platform

#

To move projects, job templates, schedules and inventory groups from AWX or Ansible Automation Platform:

  1. On a machine that can reach AWX or AAP, install the awx command and export:

    pip install awxkit
    awx export --projects --job_templates --inventory --inventory_sources --schedules > awx.json
  2. In Gardience, open Automation > Projects and, under Import from AWX or Ansible Automation Platform, choose the file and Preview.
  3. Read the preview. Nothing is created until you choose Import.
From AWX or AAPBecomes in Gardience
Git project (https or SSH address, branch, update on launch, allow branch override)Git project (an SSH project gets a new deploy key to add)
Job template (playbook, survey, extra variables, limit, tags, skip tags, check mode)Runbook with a form
Survey text, number and choice questionsForm fields
Survey password questionsA vault secret of the same name, passed by the runbook
Inventory and its groupsNode groups of the machines Gardience manages, matched by name or short name
Inventory sources (Amazon EC2, Azure, VMware vCenter, Google Compute Engine, sourced from a project)Inventory sources with the same plugin and source variables, the credential type with the vault secrets to fill in, and the schedule, imported turned off
Weekly, daily and monthly (nth or last weekday) schedulesSchedules, imported turned off

An inventory with sources gets its groups from those sources at each sync, so its static groups are not imported as well. After you fill in each source's credential and sync it, choose the group SOURCE.all (or a narrower one) as the default of the runbooks that used that inventory; the preview names the source for each one. Sources AWX calls Satellite, OpenStack, RHV, controller, Insights, or Terraform come over with their plugin, but those collections do not ship with Gardience: add the collection to a project's requirements.yml and use the inventory from that project. Custom scripts from old AWX versions and constructed inventories are not imported (add keyed_groups, groups, and compose to a source's plugin config instead).

The preview lists everything that does not carry over, and why. Repository tokens are not in exports (store them in the vault and set them on the project). Machine credentials are not needed, because Gardience reaches machines over Salt. Workflow templates, notifications, teams, roles, custom execution environments and schedules other than daily, weekly or the nth weekday of the month are not imported. Imported schedules start turned off, so nothing runs until an admin turns each one on.

Projects without Git

#

Local projects keep playbooks, states and scripts on the Gardience server, in folders, with no Git host. On Automation > Projects, choose New local project and give it a name. It starts with playbooks, states and scripts folders. Admins work in its file browser:

Playbooks in a local project become runbooks with Make a runbook, and states in its states folder publish under Automation > States (see States). Every change is in the audit log as project.file_saved. Under the hood each local project is a Git repository on the server, so its history is a real commit history.

You can also copy a project folder into srv/ansible/projects/ in your Gardience install directory, for example srv/ansible/projects/webapp/ with site.yml inside it. It appears on the Projects page as shipped with the server, and Make a runbook works the same way.

Ask the AI assistant for a playbook

#

Ask Ask Gardience for one in plain words, for example "write an Ansible playbook that runs yum update on the RHEL and Oracle machines". It shows the playbook and the node group; Dry run runs it in check mode, Run for real runs it. The playbook is saved in your own upload folder, so you can run it again with gdn or the API, and only you can run it. Running a playbook needs command-execution rights, as above. See AI assistant.

Upload a playbook with gdn

#

The gdn command line runs a playbook file from your own computer through Gardience. It needs Python 3 and an API key with the Operate scope.

  1. In Administration > Settings, under API keys, create a key with the scope Operate (request runbooks). Copy it; it is shown once.
  2. Download gdn and sign in. Replace gardience.example.com with your server's address:

    curl -fsSLo gdn https://gardience.example.com/gardience/cli/gdn && chmod +x gdn
    ./gdn login https://gardience.example.com

    If the server uses a certificate your computer does not trust, pass it with --ca, for example ./gdn login https://gardience.example.com --ca gardience.crt.

  3. Run the playbook on a node group:

    ./gdn playbook site.yml -l webservers --check
    ./gdn playbook site.yml -l webservers --secrets db_password

Options:

OptionMeaning
-l, --limitThe node group to run on (required).
--checkCheck mode: show what would change.
--secretsVault secret names, separated by commas.
--reasonA reason shown with the request.
--no-waitStart the run and return. Follow it with ./gdn status RUN_ID.

What happens to an upload:

Local mode (Linux)

#

In local mode, each Linux node runs the playbook against itself. Gardience copies the project to the node over the Salt connection.

Before the first run, install the Ansible runtime on the nodes by applying the Salt state ansible.runtime. You can do this with a custom runbook whose Salt function is state.apply and whose Arguments is ansible.runtime. The state installs ansible-core 2.18 and the ansible.posix collection into /opt/gardience-ansible, away from the system Python.

To run a playbook, use the Run an Ansible playbook (Linux) runbook. Its form has the same fields as controller mode, plus Login banner text, which the demo playbook uses. Projects come from the same srv/ansible/projects/ folder.

Local mode does not run on Windows nodes. Use controller mode for Windows.

Secrets in playbooks

#

List the secret names in the runbook's Vault secrets field, or with --secrets in gdn. In the playbook, refer to each secret as a variable with the same name:

- hosts: all
  tasks:
    - name: Write the database password
      ansible.builtin.copy:
        content: "{{ db_password }}"
        dest: /etc/app/db.pass
        mode: "0600"
#
Gardience by Bouziden Management LLC.