To run a command on an Ansible host, you can use the command module in an Ansible playbook. Here is an example playbook that runs the hostname command on a remote host:
- name: Run hostname command on remote host
hosts: my_host
tasks:
- name: Run hostname command
command: hostname
In this example, replace my_host with the hostname or IP address of your Ansible host.
You can save this playbook in a file with a .yml extension, for example, my_playbook.yml. Then, to run this playbook on the Ansible host, use the following command:
ansible-playbook my_playbook.yml
This will execute the playbook and run the hostname command on the remote host. You can replace hostname with any other command that you want to run on the remote host.
Comments (0)