HiveBrain v1.2.0
Get Started
← Back to all entries
snippetbashTip

ansible — Manage groups of computers remotely over SSH. (use the `/etc/ansible/hosts` file to add new groups/h

Submitted by: @import:tldr-pages··
0
Viewed 0 times
ansiblecommandremotelymanagecliovergroupscomputers

Problem

How to use the ansible command: Manage groups of computers remotely over SSH. (use the /etc/ansible/hosts file to add new groups/hosts). Some subcommands such as galaxy have their own usage documentation. More information: <https://docs.ansible.com/projects/ansible/latest/cli/ansible.html>.

Solution

ansible — Manage groups of computers remotely over SSH. (use the /etc/ansible/hosts file to add new groups/hosts). Some subcommands such as galaxy have their own usage documentation. More information: <https://docs.ansible.com/projects/ansible/latest/cli/ansible.html>.

List hosts belonging to a group:
ansible {{group}} --list-hosts


Ping a group of hosts by invoking the ping module:
ansible {{group}} {{[-m|--module-name]}} ping


Display facts about a group of hosts by invoking the setup module:
ansible {{group}} {{[-m|--module-name]}} setup


Execute a command on a group of hosts by invoking command module with arguments:
ansible {{group}} {{[-m|--module-name]}} command {{[-a|--args]}} '{{my_command}}'


Execute a command with administrative privileges:
ansible {{group}} {{[-b|--become]}} --ask-become-pass {{[-m|--module-name]}} command {{[-a|--args]}} '{{my_command}}'


Execute a command using a custom inventory file:
ansible {{group}} {{[-i|--inventory]}} {{inventory_file}} {{[-m|--module-name]}} command {{[-a|--args]}} '{{my_command}}'


List the groups in an inventory:
ansible localhost {{[-m|--module-name]}} debug {{[-a|--args]}} '{{var=groups.keys()}}'

Code Snippets

List hosts belonging to a group

ansible {{group}} --list-hosts

Ping a group of hosts by invoking the ping module

ansible {{group}} {{[-m|--module-name]}} ping

Display facts about a group of hosts by invoking the setup module

ansible {{group}} {{[-m|--module-name]}} setup

Execute a command on a group of hosts by invoking command module with arguments

ansible {{group}} {{[-m|--module-name]}} command {{[-a|--args]}} '{{my_command}}'

Execute a command with administrative privileges

ansible {{group}} {{[-b|--become]}} --ask-become-pass {{[-m|--module-name]}} command {{[-a|--args]}} '{{my_command}}'

Context

tldr-pages: common/ansible

Revisions (0)

No revisions yet.