Ad-Hoc Ansible Commands Flashcards
what id ad-hoc command
Are effectively one-liners
One can run ansible either ad-hoc or as a playbook
Use cases for ad-hoc
- Operational commands
- -checking logs
- -daemon control
- -process management - Informational commands
- -check installed software
- -check system properties - Research
- - work with unfamiliar modules on test systems
ad-hoc vs playbook
1. ad-hoc: command ansible playbook: command ansible-playbook 2. ad-hoc: effective for one-time command, operational activities playbook: effective for deployment, routine tasks 3. ad-hoc similar to bash command playbook similar to bash script
Common modules
Ping, no params Setup- gather ansible facts, no params Yum- params: name and state Service- control daemons params: name and state User- manipulate system users parans: name Copy- copy files params: src and dest File- works with files params: path Git -interact with git repo params: repo and dest
Install/remove package on remote host
ansible -i inventory antony1 -b -m yum -a “name=htop state=latest”
ansible -i inventory antony1 -b -m yum -a “name=htop state=absent”
Working with file module: Create a file on remote host Check if file exists Update permissions of the file Change the owner of file on remote host
ansible -i inventory antony1 -b -m file -a “path=/home/cloud_user/file1 state=touch”
ansible -i inventory antony1 -m file -a “path=/home/cloud_user/file1”
ansible -i inventory antony1 -b -m file -a “path=/home/cloud_user/file1 mode=0444”
ansible -i inventory antony1 -b -m file -a “path=/home/cloud_user/file1 owner=cloud_user”
ansible all -i inventory -b -m copy -a “src=/home/ansible/.ssh/id_rsa.pub dest=/home/supervisor/.ssh/authorized_keys/ owner=supervisor mode=0600”
Working with user module:
create a user on remote host
ansible -i inventory antony1 -b -m user -a “name=avance”
ansible -i inventory antony1 -b -m user -a “name=avance append=yes group=wheel”
Ensure auditd
Is Enabled and Running on All Hosts
ansible all -b -m service -a “name=auditd state=started enabled=yes”