From 586d0826857c3c69d9dd8094098ce8851b2ac67a Mon Sep 17 00:00:00 2001 From: RadinPirouz <75082987+RadinPirouz@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:08:54 +0330 Subject: [PATCH] Create Document.md --- Ansible/Document.md | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Ansible/Document.md diff --git a/Ansible/Document.md b/Ansible/Document.md new file mode 100644 index 0000000..0b5cbb2 --- /dev/null +++ b/Ansible/Document.md @@ -0,0 +1,76 @@ + +# Ansible Module Usage + +Ansible modules are standalone scripts that can be used within Ansible to perform various tasks on managed nodes. Here are some examples of using Ansible modules: + +## Basic Module Execution + +To execute a module against all hosts in your inventory file: + +```bash +ansible -m all -i +``` + +Example: + +```bash +ansible -m ping all -i server.ini +``` + +## Module Execution with Arguments + +You can pass arguments to modules using the `-a` flag: + +```bash +ansible -m -a -i +``` + +Examples: + +```bash +ansible -m command -a "uptime" -i server.ini all +ansible -m command -a "uname -a" -i server.ini all +``` + +## Running Commands as sudo + +If the command requires root privileges, you can use the `--become` or `-b` flag: + +```bash +ansible -m -a "" --become -i +``` + +Example: + +```bash +ansible -m command -a "sudo reboot" -i server.ini all +``` + +## More Examples + +Here are some additional examples demonstrating Ansible module usage: + +- Gathering facts from all hosts: + +```bash +ansible -m setup all -i server.ini +``` + +- Copying a file to all hosts: + +```bash +ansible -m copy -a "src=/path/to/src/file dest=/path/to/destination/" -i server.ini all +``` + +- Installing a package using apt module: + +```bash +ansible -m apt -a "name= state=present" -i server.ini all +``` + +- Restarting a service: + +```bash +ansible -m service -a "name= state=restarted" -i server.ini all +``` +