Command Line Flashcards
Command to check to get the hostname of a group of machines: “multi”
ansible multi -a “hostname”
Command to check to get the hostname of a group of machines: “multi”, one node at a time.
ansible multi -a “hostname” -f 1
Command to check to get the amout of memory of a group of machines: “multi”
ansible multi -a “free -m”
Command to install ntp on a group of machines: “multi”
ansible multi -b -m yum a “name=ntp state=present”
Command to add an “admin” group on a group of machines: “multi”
ansible multi -b -m group -a “state=present name=admin”
Add a user “john” on a group of machines: “multi” in the group admin
ansible multi -m user -b -a “state=present name=john group=admin createhome=yes”
Install git on “host” using the generic ansible module dedicated for this purpose
ansible host -m package -a “name=git state=present”
Check file permissions of a folder /etc/environment
ansible multi -m stat -a “path=/etc/environment”
Recursively copy folder /etc/hosts into /tmp/hosts
ansible multi -m copy -a “src=/etc/hosts dest=/tmp/hosts”
Copy content of folder /etc/hosts into /tmp/hosts
ansible multi -m copy -a “src=/etc/hosts/ dest=/tmp/hosts”
Create a directory /tmp/dest
ansible multi -m file -a “state=directory mode=644 dest=/tmp/dest”
Create a symlink from /tmp/dest to /etc/dest
ansible multi -m file -a “state=link dest=/etc/dest src=/tmp/dest”
Delete a directory /tmp/dest
ansible multi -m file -a “state=absent dest=/tmp/dest”
Set a cron job to run the script /etc/dc/script.sh every 4h
ansible hosts -m cron -a “hour=4 job=/etc/dc/script.sh name=every-four-hour-job”
Stp the cron job every-four-hour-job
ansible hosts -m cron -a “name=every-four-hour-job state=absent”