Difference between revisions of "Ansible"
Jump to navigation
Jump to search
| Line 1: | Line 1: | ||
= | = Ansible = | ||
== Running ad-hoc commands == | == Running ad-hoc commands == | ||
<code>ansible all --key-file <path to key-file> -i <inventory> -m <module></code> | <code>ansible all --key-file <path to key-file> -i <inventory> -m <module></code> | ||
== Example ansible config == | |||
<pre>[defaults] | |||
inventory = <inventory file> | |||
private_key_file = <path to key-file></pre> | |||
== Useful commands == | |||
<code>ansible all --list-hosts</code> List target hosts</br> | |||
<code>ansible all -m gather_facts</code> List target facts</br> | |||
<code>ansible all -m gather_facts --limit <host></code> List target facts, limited to <host></br> | |||
=== Become === | |||
The sudo password must be the same on control and target nodes.</br> | |||
<code>ansible all -m apt -a update_cache=true --become --ask-become-pass</code> Run apt update with sudo and ask for password</br> | |||
<code>ansible all -m apt -a "name=vim-nox state=latest" --become --ask-become-pass</code> Install newest version of vim-nox</br> | |||
<code>ansible all -m apt -a upgrade=full --become --ask-become-pass</code> Upgrade all packages</br> | |||
Revision as of 15:30, 3 September 2025
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