Ansible

From 6bit.ch wiki
Revision as of 15:30, 3 September 2025 by Xbl (talk | contribs)
Jump to navigation Jump to search

Ansible

Running ad-hoc commands

ansible all --key-file <path to key-file> -i <inventory> -m <module>

Example ansible config

[defaults]
inventory = <inventory file>
private_key_file = <path to key-file>

Useful commands

ansible all --list-hosts List target hosts
ansible all -m gather_facts List target facts
ansible all -m gather_facts --limit <host> List target facts, limited to <host>

Become

The sudo password must be the same on control and target nodes.
ansible all -m apt -a update_cache=true --become --ask-become-pass Run apt update with sudo and ask for password
ansible all -m apt -a "name=vim-nox state=latest" --become --ask-become-pass Install newest version of vim-nox
ansible all -m apt -a upgrade=full --become --ask-become-pass Upgrade all packages