# ansible command

**1.Pinging All Hosts**:

* Check connectivity to all hosts in the inventory:
    
* ```yaml
        ansible all -m ping
    ```
    
* **2.Copying Files**:
    
    * Copy a file from the local machine to remote hosts:
        
    * ```yaml
            ansible target_hosts -m copy -a "src=/path/to/local_file.txt dest=/remote/path/"
        ```
        
        **3.Checking Free Disk Space**:
        
        * Check free disk space on remote hosts:
            
        * ```yaml
                ansible target_hosts -m shell -a "df -h"
            ```
            
        * **4.Running a Playbook**:
            
            * Execute a playbook named `playbook.yml` on the `target_hosts` group:
                
        
        ```yaml
        ansible-playbook -i inventory.ini playbook.yml
        ```
        
        **5.Running Multiple Playbooks**:
        
        * Execute multiple playbooks sequentially:
            
        * ```yaml
                ansible-playbook playbook1.yml playbook2.yml
            ```
            
        
        **6.Reboot remote hosts**
        
    * ```yaml
        ansible target_hosts -m reboot
        ```
        
        **7.Check if a service is running**
        
    * ```yaml
        ansible target_hosts -m service -a "name=httpd state=started"
        ```
        
        **8.Check system information**
        
    * ```yaml
        ansible all -m setup
        ```
        
        **9.Check system uptime**
        
    * ```yaml
        ansible target_hosts -m shell -a "uptime"
        ```
        
        **10.Restart a service**
        
    * ```yaml
        ansible target_hosts -m service -a "name=apache2 state=restarted"
        ```
