ansible

Useful commands
  • Issue reboot
    • ansible pacman -e 'ansible_user=root' -a "/usr/bin/reboot"
  • ansible ping:
    • ansible arch -m ping -u root
  • Get information about a file:
    • ansible kerflooey -m stat -a "path=/etc/environment"
  • Copy a file to the servers:
    • $ ansible arch -m copy -a "src=/etc/hosts dest=/tmp/hosts"
  • Retrieve a file from the servers:
    • $ ansible multi -b -m fetch -a "src=/etc/hosts dest=/tmp"
Create directories and files
  • Here’s how to create a directory:
    • $ ansible multi -m file -a "dest=/tmp/test mode=644 state=directory"
  • Here’s how to create a symlink (set state=link):
    • ansible multi -m file -a "src=/src/file dest=/dest/symlink state=link"
  • Delete directories and files:
    • $ ansible multi -m file -a "dest=/tmp/test state=absent"
ansible-playbook playbook.yml --become --become-user=janedoe --ask-become-pass

* --inventory=PATH (-i PATH): Define a custom inventory file (default is the default Ansible inventory file, usually located at /etc/ansible/hosts).
* --verbose (-v): Verbose mode (show all output, including output from successful options). You can pass in -vvvv to give every minute detail.
* --extra-vars=VARS (-e VARS): Define variables to be used in the playbook, in "key=value,key=value" format.
* --forks=NUM (-f NUM): Number for forks (integer). Set this to a number higher than 5 to increase the number of servers on which Ansible will run tasks concurrently.
* --connection=TYPE (-c TYPE): The type of connection which will be used (this defaults to ssh; you might sometimes want to use local to run a playbook on your local machine, or on a remote server via cron).
* --check: Run the playbook in Check Mode (‘Dry Run’); all tasks defined in the playbook will be checked against all hosts, but none will actually be run.

ansible pacman -e 'ansible_user=root' -a "/usr/bin/somecmd"
ansible-playbook archlinux-ct-init.yml --limit=init
ansible pacman -e 'ansible_user=root' -a "/usr/bin/timedatectl set-timezone Europe/Copenhagen"

Last modified: Wed Jun 11 23:02:56 2025