ansible adhoc
时间: 2023-07-21 21:07:07 浏览: 134
Ansible Ad-hoc commands are one-liners that allow you to perform tasks quickly on remote servers without the need to write a playbook. They are useful for executing simple, one-off tasks like restarting a service, checking disk space, or running a command.
Here's an example of an Ansible Ad-hoc command to check the disk space on a remote server:
```
ansible all -i inventory -m shell -a 'df -h'
```
This command uses the `shell` module to run the `df -h` command on all servers defined in the inventory file. The output will show the disk usage on each server.
Other modules that can be used in Ad-hoc commands include `ping`, `copy`, `yum`, and `apt`. The `-m` flag is used to specify the module, and the `-a` flag is used to pass arguments to the module.
While Ad-hoc commands are useful for quick tasks, it's recommended to use playbooks for more complex tasks or to perform repetitive tasks.
阅读全文