Random Adhoc Commands
This is a collection of random adhoc commands that I have found useful.
Restart a service
ansible all -i ../terraform_ddp/inventory.yml -b -m service -a 'name=sshd state=restarted'
Change DNS Server
This was used on a set of Almalinux servers to change the DNS server to a local DNS server, since the packer/terraform setup did not set the DNS server correctly on all nodes.
export ANSIBLE_SSH_ARGS="-F ../terraform_ddp/ssh.cfg"ansible all -i ../terraform_ddp/inventory.yml -b -m shell -a ' \UUID=$(nmcli -t -f NAME,UUID,DEVICE,ACTIVE c show --active | grep ens | cut -d: -f2) && \nmcli con modify "$UUID" ipv4.dns "<IP>" ipv4.ignore-auto-dns yes && \nmcli con up "$UUID"'
Validate root login via ssh
ansible all -i ../terraform_ddp/inventory.yml -b -m shell -a "\grep -E '^PermitRootLogin' /etc/ssh/sshd_config || echo 'PermitRootLogin not set'"
Enable root login via ssh
ansible all -i ../terraform_ddp/inventory.yml -b -m lineinfile -a 'path=/etc/ssh/sshd_configregexp="^PermitRootLogin"line="PermitRootLogin yes"create=yes'