---
title: "Dosh"
description: "Dosh runs a specified command on selected Opsview hosts using the Ansible shell module and requires root access and the jq utility. The FAQ explains usage examples, prerequisites, and an alternative method using Ansible on the orchestrator."
url: "https://docs.itrsgroup.com/docs/faq/opsview/4922950487965-opsview-dosh/index.html"
---
Run a given command on specified Opsview hosts.

## Synopsis

```
/opt/opsview/support-scripts/bin/dosh
dosh -l
dosh -t opsview_collectors <command to run>
```

## Description

Run a given command on a selection of the [Opsview hosts](https://docs.itrsgroup.com/docs/faq/opsview/4920387360029-opsview-opsview-host/index.html) by using the Ansible ‘shell’ module.

Must be run on your [deployment host](https://docs.itrsgroup.com/docs/faq/opsview/4920324786973-opsview-deployment-host/index.html) as the `root` user. Requires the utility `jq` be installed.

## Options

| Option | Purpose | Default |
| --- | --- | --- |
| `-h` | Terse help output |  |
| `-l` | List available host groupings |  |
| `-m <module>` | Specify the Ansible module to use | Shell |
| `-t <target>` | Set the host grouping to `<target>` | `opsview_collector:!opsview_orchestrator` |

## Arguments

| Argument | Purpose |
| --- | --- |
| `<commands to run>` | The command to run on the remote servers (or arguments to pass to the Ansible module) |

## Files

| File | Description |
| --- | --- |
| `/opt/opsview/deploy/etc/opsview_deploy.yml` | Configuration file used by Ansible |

## Examples

1. Run `hostname` on all [collectors](https://docs.itrsgroup.com/docs/faq/opsview/4919470073373-opsview-collector/index.html):

```
/opt/opsview/supportscripts/bin/dosh -t opsview_collectors hostname
```

2. Run `uptime -p` on all collectors in the cluster\_fr [cluster](https://docs.itrsgroup.com/docs/faq/opsview/4920301079581-opsview-collector-cluster/index.html):

```
/opt/opsview/supportscripts/bin/dosh -t opsview_cluster_cluster_fr uptime -p
```

3. Run `cat /opt/opsview/var/machine.ref` on all collectors but not the [orchestrator](https://docs.itrsgroup.com/docs/faq/opsview/4920429084957-opsview-orchestrator/index.html):

```
/opt/opsview/supportscripts/bin/dosh -t 'opsview_collector:!opsview_orchestrator' cat /opt/opsview/var/machine.ref
```

## Alternative: Ansible

You can achieve the same effects of `dosh` by using Ansible on your orchestrator.

Before running any of the following commands for the first time in a shell session, you need to log in as `root` and use this `source` command:

```
source /opt/opsview/deploy/bin/rc.ansible
```

### List available host groupings

This command requires the `jq` package be installed.

```
ansible-inventory  --list | jq -r '.opsview_all.children[]'
```

### Run commands on hosts

```
ansible -m shell -a '<command>' '<hosts>'
```

For example, run `hostname` on every Opsview host:

```
ansible -m shell -a 'hostname' 'opsview_all'
```


