2016-11-23 18:29:38 +07:00
|
|
|
# ansible
|
|
|
|
|
2021-09-13 10:21:21 +02:00
|
|
|
> Manage groups of computers remotely over SSH. (use the `/etc/ansible/hosts` file to add new groups/hosts).
|
2024-10-04 21:14:41 +02:00
|
|
|
> Some subcommands such as `galaxy` have their own usage documentation.
|
2025-03-28 05:26:23 +02:00
|
|
|
> More information: <https://docs.ansible.com/ansible/latest/cli/ansible.html>.
|
2016-11-23 18:29:38 +07:00
|
|
|
|
|
|
|
- List hosts belonging to a group:
|
|
|
|
|
|
|
|
`ansible {{group}} --list-hosts`
|
|
|
|
|
2025-03-28 05:26:23 +02:00
|
|
|
- Ping a group of hosts by invoking the ping module:
|
2016-11-23 18:29:38 +07:00
|
|
|
|
2025-03-28 05:26:23 +02:00
|
|
|
`ansible {{group}} {{[-m|--module-name]}} ping`
|
2016-11-23 18:29:38 +07:00
|
|
|
|
2024-02-09 11:34:08 -03:00
|
|
|
- Display facts about a group of hosts by invoking the setup [m]odule:
|
2016-11-23 18:29:38 +07:00
|
|
|
|
2025-03-28 05:26:23 +02:00
|
|
|
`ansible {{group}} {{[-m|--module-name]}} setup`
|
2016-11-23 18:29:38 +07:00
|
|
|
|
|
|
|
- Execute a command on a group of hosts by invoking command module with arguments:
|
|
|
|
|
2025-03-28 05:26:23 +02:00
|
|
|
`ansible {{group}} {{[-m|--module-name]}} command {{[-a|--args]}} '{{my_command}}'`
|
2016-11-23 18:29:38 +07:00
|
|
|
|
|
|
|
- Execute a command with administrative privileges:
|
|
|
|
|
2025-03-28 05:26:23 +02:00
|
|
|
`ansible {{group}} {{[-b|--become]}} --ask-become-pass {{[-m|--module-name]}} command {{[-a|--args]}} '{{my_command}}'`
|
2016-11-23 18:29:38 +07:00
|
|
|
|
|
|
|
- Execute a command using a custom inventory file:
|
|
|
|
|
2025-03-28 05:26:23 +02:00
|
|
|
`ansible {{group}} {{[-i|--inventory]}} {{inventory_file}} {{[-m|--module-name]}} command {{[-a|--args]}} '{{my_command}}'`
|
2021-04-15 14:30:12 -04:00
|
|
|
|
|
|
|
- List the groups in an inventory:
|
|
|
|
|
2025-03-28 05:26:23 +02:00
|
|
|
`ansible localhost {{[-m|--module-name]}} debug {{[-a|--args]}} '{{var=groups.keys()}}'`
|