Working with Ansible playbooks in Atlas

Use Tanium™ Atlas to run your existing Ansible playbooks on Tanium-managed Linux endpoints. Atlas uses natural language prompts to start playbook runs, report the result for each endpoint, and return the Ansible output for a specific endpoint, so you can manage Ansible playbooks alongside other tasks on the same page. For more information about Atlas, see Tanium Atlas User Guide.

The Tanium™ Client delivers the playbook to each targeted endpoint, and Ansible runs it locally against that endpoint only. Results return through Tanium sensors, the same as any other endpoint data.

Atlas runs playbooks through a single automation operation, automate.ansible_playbook.run.v2, which appears by name in approval cards and run summaries. Every run requires your approval before it reaches an endpoint.

Note: Ansible playbook runs are available to Tanium Cloud customers with Automate and Atlas, and are supported on Linux endpoints only. Ansible playbook runs in Atlas are not enabled by default. To enable these playbook runs, contact Tanium Support.

Before you begin

  • You must have permission to deploy actions to the computer group that you target, and the Automate permissions to run automation operations. For more information, see Automate requirements.
  • To upload a playbook archive, you must have the write package permission on a content set.
  • Targeted endpoints must meet the requirements. For more information, see Endpoint requirements.
  • Before your first run, Automate must have a platform token for your user. For more information, see Register an Automate platform token.

Endpoint requirements

Targeted endpoints must run Linux and have the Tanium Client installed. Automate does not install Ansible on endpoints. Make sure that each targeted endpoint meets the following requirements:

  • Python 3.10 or later and ansible-core 2.11 or later, installed system-wide. The Tanium Client runs as root with the system PATH and locates Ansible with command -v ansible-playbook, so an installation in /usr/bin or /usr/local/bin works. A user-level installation, such as pip install --user, a virtual environment, or pipx, is not on that path. The run then fails before any task runs and returns the message ansible-playbook is not on PATH; install Python and ansible-core on this endpoint.
  • An ansible-core version that the Python version on the endpoint supports. Any Ansible Galaxy collections that you vendor must support the ansible-core version on the endpoint.
  • setsid, which is part of util-linux and is included in all mainstream Linux distributions.

The ansible-playbook binary runs under the Python version that it was installed with. Automate does not select or change this version. Tanium helper scripts on the endpoint use the Python version that is included with the Tanium Client, so the Python version on the endpoint does not need to match the Python version bundled with the Tanium Client.

To verify an endpoint before your first playbook run, run the following command on the endpoint as root:

CODE
command -v ansible-playbook && ansible-playbook --version

Register an Automate platform token

An Ansible playbook run uses the permissions of the user who starts the run, not those of a service account, so Automate must have a platform token for your user. Automate creates this token the first time that you save a playbook.

  1. From the Main menu, go to Automate as the same user and persona that you use for Atlas.
  2. Create and save any playbook. You can delete the playbook after you save it. For more information, see Building playbooks.

The token is valid for seven days and renews automatically while you continue to use Automate. If you have not used Automate for more than seven days, save a playbook again.

If Automate does not have a platform token for your user, the playbook run fails within seconds, returns the message the run-as user has no usable Automate platform token; register one from the Automate workbench, and does not reach any endpoint.

Configure Atlas for Ansible playbook runs

Include the automate.ansible_playbook.run.v2 operation in every prompt that starts a playbook run. In some cases, Atlas does not find the operation, asks you to confirm the request in the Chat pane instead of returning an approval card, or declines the request because the operation changes endpoints. If this happens, add the following instructions to the AI Agent Instructions field under User Preferences in Atlas. You need to add these instructions only one time.

CODE
Ansible playbook runs

- To run an Ansible playbook, use the automation operation automate.ansible_playbook.run.v2 through a composition run. The playbook steps, packages, and sensors behind it are internal to the operation.
- This operation writes to endpoints and is registered as destructive. Request the approval prompt rather than asking me to confirm first, and do not set require_read_only.
- Default to a one-off run. Register a composition only when I ask for one, which takes two approvals.
- Resolve a computer group name to its ID yourself. When I give an archive hash and an entry-point playbook, use the archive form of the source.
- Poll the run to a terminal state before reporting, then give the run ID, status, play statistics, and per-endpoint detail. For endpoint output, ask the Automate - Ansible Run Log sensor with the run ID.

Playbook source options for Atlas

You can provide a playbook to Atlas as inline YAML or as an uploaded archive.

Table 1. Playbook source methods

Method

Description

When to use

Inline YAML

Paste the playbook into the Atlas prompt. Limited to a single playbook file with no roles, files, or collections.

A single-task fix or a quick drift check, such as a package installed across a computer group, or a baseline configuration file with expected contents.

Uploaded archive

Archive your playbook repository, upload it to the Tanium Server, and provide the returned SHA-256 hash and the path of an entry-point playbook inside the archive.

Playbooks that include roles, templates, files, or Ansible Galaxy collection dependencies.

Automate does not connect to your Git repository or download Ansible content on your behalf, and endpoints do not connect to Ansible Galaxy or the internet. Because you build the upload in your own environment, repository credentials and internal repository content are not sent to Tanium.

To build and upload a playbook archive, see Build and upload a playbook archive.

Build and upload a playbook archive

Perform the following steps from the root of your playbook repository, on a machine that has ansible-galaxy installed and internet access.

  1. Vendor the collections that your playbooks require.
    CODE
    ansible-galaxy collection install -r requirements.yml -p ./collections --force
  2. Archive the directory tree. Exclude the tests directories of vendored collections, which are large and do not run.
    CODE
    tar --exclude-vcs --exclude='./collections/ansible_collections/*/*/tests' -czf playbooks.tar.gz .
  3. Upload the archive to the Tanium Server with an API token. Archives cannot exceed 64 MB. To create an API token, from the Main menu go to Administration > Permissions > API Tokens.
    CODE
    curl -s -X POST "https://<your tanium server>/api/v2/upload_file_stream" \
      -H "session: $TANIUM_TOKEN" \
      -F "file=@playbooks.tar.gz"
  4. Record the hash value from the response. Provide this hash to Atlas with the path of your entry-point playbook, such as site.yml. If you upload the same archive again, the Tanium Server returns the same hash.

Endpoint targeting for a playbook run

A playbook run targets endpoints by computer group or by computer name.

Table 2. Endpoint targeting methods

Method

Description

Computer group

Include the name of an existing computer group in your prompt, such as All Linux or Web Servers - Prod. Atlas resolves the name to the computer group. The computer group must already exist in the Tanium Console. The playbook run does not create computer groups or evaluate ad hoc filters.

List of computer names

Include the endpoint names in your prompt. Use this method to remediate the specific endpoints that a check mode run reported as drifted.

To target a set of endpoints that no existing computer group describes, create the computer group in the Tanium Console, and then include its name in your prompt.

Note: You cannot use action groups, free-form questions, or sensor filters to target a playbook run, and per-host hosts: selection within the playbook is not applied. The hosts: value of your play is rewritten to all at run time, and each endpoint runs the play against itself only.

Run an Ansible playbook in Atlas

Run an Ansible playbook on the endpoints in a computer group, or on a list of endpoints that you specify.

  1. From the Main menu, click Atlas Atlas to open the Atlas UI.
  2. In the Atlas Chat pane, enter a prompt that includes the automate.ansible_playbook.run.v2 operation, the mode, the target, and the playbook source. Use mode "run" to apply the playbook, or mode "check" to perform a dry run. For example:
    CODE
    Create and run a composition that invokes the automate.ansible_playbook.run.v2 operation. Use mode "run", computer group name "RHEL Endpoints", and this inline playbook:
    - hosts: all
      tasks:
        - name: ensure ntp is installed
          package:
            name: ntp
            state: present

    To use an uploaded archive, provide the hash and the entry-point playbook instead of inline YAML. For example:

    PYTHON
    Create and run a composition that invokes the automate.ansible_playbook.run.v2 operation, using the archive form of the source.
    I've uploaded my Ansible bundle to the Tanium Server via upload_file_stream: hash <sha256 from the upload>, entry-point playbook site.yml.
    Use mode "run", computer group name "RHEL Endpoints".
  3. Review the approval card, which shows the mode, the playbook source, and the target. Then click Approve.
    Important: A run mode playbook run that targets a computer group is treated as high risk. Type CONFIRM in the confirmation field to enable Approve.
  4. Wait for the playbook run to reach a terminal state. Endpoints report results once a minute, and the run ends when every endpoint that started the play has a final result. Atlas polls the run and reports its progress. A playbook run remains in progress for several minutes while each endpoint stages the playbook and runs the play.
    Note: A playbook run has a default deadline of four hours. Endpoints that do not report a result before the deadline are listed in the run results.
  5. Review the run results. For more information, see Review Ansible playbook run results.
Note: A prompt that asks Atlas to create and run a composition performs two actions and returns two approval cards: one to register the composition and one to run it. A registered composition stores the playbook source, mode, and target, so later runs of that composition require one approval and no new upload. To run a playbook one time with a single approval, ask for a one-off run and specify that Atlas must not register a composition.

Check endpoints for configuration drift

Check mode is the Ansible dry run. The play reports the changes that it would make and does not write to the endpoint. If the playbook would change any endpoint, the playbook run returns DRIFTED and lists each of those endpoints.

  1. From the Main menu, click Atlas Atlas to open the Atlas UI.
  2. In the Atlas Chat pane, enter a prompt that specifies mode "check". For example:
    CODE
    Run automate.ansible_playbook.run.v2 as a one-off run (do not register a composition), mode "check", computer group "RHEL Endpoints", with this inline playbook:
    - hosts: all
      gather_facts: false
      become: true
      tasks:
        - name: baseline file is present with the expected content
          ansible.builtin.copy:
            dest: /etc/baseline.conf
            content: |
              managed_by=tanium
              baseline=1
            mode: "0644"
  3. Approve the run and review the results. Each endpoint that the playbook would change is listed as DRIFTED with the number of tasks that would change. Nothing is written to any endpoint.
  4. To remediate the drifted endpoints, ask Atlas to run the same playbook in run mode against only those endpoints. Atlas targets the endpoints by computer name instead of by computer group.
  5. (Optional) Run the check again to confirm the result. A run that reports changed=0 and lists no drifted endpoints indicates that every targeted endpoint matches the playbook.

Ansible playbook run results

A playbook run reports its status, the Ansible play statistics, and the detail for each endpoint that reported an issue.

Ansible counts tasks, not endpoints. The ok count includes every task that completed, and the changed count includes only the tasks that modified the endpoint. An idempotent playbook reports changed=0 when you run it again.

Table 3. Playbook run statuses

Status

Description

SUCCEEDED

Every endpoint completed the play with no failures. In check mode, no endpoint would change.

DRIFTED

A check mode run found at least one endpoint that the playbook would change.

FAILED

An endpoint failed or was unreachable, an endpoint did not report a result, or the playbook run could not start.

CANCELED

The playbook run was stopped. Endpoints that had not started the play do not start it. Endpoints that are running the play complete it.

For more information, see Endpoint-level results. To review the full Ansible output from an endpoint, see Ansible output from an endpoint.

Endpoint-level results

An endpoint is listed in the run results only if it reported an issue. Each listed endpoint includes a result kind, and a failed endpoint also includes the task that ended the play and the message that Ansible returned.

Table 4. Endpoint result kinds

Kind

Description

Recommended action

FAILED

At least one Ansible task failed on the endpoint.

Review the detail for the endpoint, and then ask Atlas for the run log.

DRIFTED

In check mode, the playbook would change the endpoint.

Run the playbook in run mode to remediate the endpoint, or investigate the cause of the drift.

LAUNCH_FAILED

The endpoint received the playbook run, but the run ended before Ansible started. This result usually indicates that Python 3 or ansible-core is not installed on the system path.

For more information, see Endpoint requirements. A playbook run ends on these endpoints without waiting for the deadline.

UNREACHABLE

Ansible could not act on the endpoint.

Review the Ansible installation on the endpoint.

STILL_RUNNING

The play was still running when the playbook run reached its deadline.

Review the endpoint later, or reduce the number of tasks in the play.

NO_RESPONSE

The playbook run started on the endpoint, but the endpoint did not report a result before the deadline.

Review the endpoint later. An endpoint without Python or Ansible installed returns LAUNCH_FAILED instead.

Ansible output from an endpoint

Two sensors return Ansible playbook run data.

Table 5. Ansible playbook run sensors

Sensor

Description

Automate - Ansible Run Recap

The playbook run asks this sensor once a minute. The sensor returns the state, the mode, and the play statistics. For a failed endpoint, it also returns the failing task and its message. Atlas uses these results for the endpoint detail in the run summary, so you do not need to ask this sensor.

Automate - Ansible Run Log

Ask this sensor to review the full Ansible output from an endpoint. The sensor takes the playbook run ID as a parameter and returns up to the last 1000 lines of the ansible-playbook output on the endpoint.

To review the full Ansible output for a specific endpoint, enter a prompt that asks for the run log sensor. For example:

CODE
Run the Tanium sensor Automate - Ansible Run Log with run_id <id> against <host>

Atlas adds the sensor results to the display pane.

Note: The Ansible run log is available on an endpoint only until the working directory for the playbook run is removed.

Troubleshoot Ansible playbook runs

If an Ansible playbook run does not perform as expected, review the following issues and resolutions.

Table 6. Ansible playbook run issues

Issue

Cause

Resolution

Atlas reports that it cannot run an Ansible playbook, or that the Ansible package and sensors are not intended for direct use.

Atlas searched the Automate playbook steps instead of the automation operation.

Include automate.ansible_playbook.run.v2 in your prompt. To configure Atlas for Ansible playbook runs, see Configure Atlas for Ansible playbook runs.

Atlas declines the request because the run must be read-only, or because the run is not permitted to write.

Atlas applied general composition guidance that does not cover Ansible playbook runs.

To configure Atlas for Ansible playbook runs, see Configure Atlas for Ansible playbook runs. If the issue continues, see Contact Tanium Support.

The playbook run fails within seconds and returns a message about an unusable Automate platform token.

Your user has not saved an Automate playbook, or has not used Automate in the last seven days.

For more information, see Register an Automate platform token.

Endpoints return LAUNCH_FAILED soon after the playbook run starts.

Python 3 or ansible-core is not on the system path on those endpoints, so the run ends before the play starts.

For more information, see Endpoint requirements.

Atlas returns two approval cards for one request.

A prompt that asks Atlas to create and run a composition performs two actions: it registers the composition, and then runs it.

Ask for a one-off run to start a single playbook run with a single approval.

The run log reports that a collection does not support the Ansible version on the endpoint.

The vendored collection requires a later ansible-core version than the Python version on the endpoint supports.

This message is a warning, and the play continues to run. To resolve the warning, specify an earlier collection version in requirements.yml and build the archive again.

Some endpoints fail with a package manager error, and other endpoints complete the play.

The package name or the repository differs by Linux distribution.

Ask Atlas for the run log of a failed endpoint to identify the expected package name. Update the Ansible playbook with the correct package name, or target a different computer group.

A run that uses a newly uploaded archive fails before reaching any endpoint.

The Tanium Server has not finished caching the archive.

Wait a few minutes and run the playbook again.

The run is rejected with vendored collection ... requires ansible-core ...

A vendored collection declares that it does not support the ansible-core version that Automate targets.

Update the collection to a version that supports current ansible-core releases and build the archive again.

An archive upload fails or is rejected.

The archive exceeds the 64 MB limit, or it was uploaded as a raw request body instead of multipart/form-data.

Confirm the archive is under 64 MB and upload it as multipart/form-data. If the issue continues, see Contact Tanium Support.

Ansible playbook run limitations

Note the following limitations for Ansible playbook runs:

  • Playbooks must run against the local endpoint only. Automate rejects plays that batch across endpoints with serial, delegate tasks to another host, or use a non-local connection. Automate also does not apply the ansible.cfg file from your repository.
  • Cross-host orchestration, such as a rolling restart in which tasks on one endpoint depend on another endpoint, is not supported.
  • Windows endpoints, macOS endpoints, and devices without the Tanium Client are not supported.
  • Ansible Vault passwords, direct Git integration, and scheduled drift checks are not supported.
  • Atlas is the only interface for Ansible playbook runs. The Automate workbench does not include a page for them.
  • Automate does not prevent two playbook runs from targeting the same endpoint at the same time.