AD HOC Command - shekharshamra/ansible-playbooks GitHub Wiki

  1. Check connectivity between servers.

    ansible webserver -m ping

  2. Copy file from source to destination

    ansible webserver -m copy -a "src=/etc/hosts dest=/tmp/hosts"

    ansible webserver -m copy -a "src=/etc/hosts dest=/tmp/hosts"

    ansible webserver -m file -a "dest=/tmp/shekhar.txt mode=600 owner=shekhar group=shekhar"

  3. Reboot server

    ansible -a "/sbin/reboot" -f 10

  4. Managing Packages A. Installing Package

     ansible <HostGroup> -m yum -a "name=httpd state=present"
    

    B. Ensure latest package is installed

     ansible <HostGroup> -m yum -a "name=acme state=latest"
    

    C. Uninstall/Remove Package

     ansible <HostGroup> -m yum -a "name=acme state=absent"
    
  5. Managing Services:

    A. Start Service

     Ansible webservers -m service -a "name=httpd state=started"
    

    B. Restart service

    ansible webservers -m service -a "name=httpd state=restarted"
    

    C. Stop Service:

    ansible webservers -m service -a "name=httpd state=stopped"
    
  6. Add User:

    ansible all -m user -a "name=foo password=<crypted password here>"
    
    ansible all -m user -a "name=foo state=absent"
    
⚠️ **GitHub.com Fallback** ⚠️