Skip to main content

Command Palette

Search for a command to run...

ansible command

adhoc command:

Updated
1 min readView as Markdown
ansible command
S

*Shreyash Bhise | Aspiring Mern Stack Developer and DevOps enthusiast,

1.Pinging All Hosts:

  • Check connectivity to all hosts in the inventory:

  •       ansible all -m ping
    
  • 2.Copying Files:

    • Copy a file from the local machine to remote hosts:

    •       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:

      •       ansible target_hosts -m shell -a "df -h"
        
      • 4.Running a Playbook:

        • Execute a playbook named playbook.yml on the target_hosts group:
        ansible-playbook -i inventory.ini playbook.yml

5.Running Multiple Playbooks:

  • Execute multiple playbooks sequentially:

  •       ansible-playbook playbook1.yml playbook2.yml
    

6.Reboot remote hosts

  •   ansible target_hosts -m reboot
    

    7.Check if a service is running

  •   ansible target_hosts -m service -a "name=httpd state=started"
    

    8.Check system information

  •   ansible all -m setup
    

    9.Check system uptime

  •   ansible target_hosts -m shell -a "uptime"
    

    10.Restart a service

  •   ansible target_hosts -m service -a "name=apache2 state=restarted"
    

More from this blog

Shreyash Bhise's blog

55 posts