Difference between revisions of "Ansible"
| (3 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
<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> | ||
== | == Ansible config == | ||
<code>ansible-config init --disabled > ansible.cfg</code> Generate a commented-out sample config</br> | |||
<pre>[defaults] | <pre>[defaults] | ||
inventory = <inventory file> | inventory = <inventory file> | ||
| Line 17: | Line 19: | ||
<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 "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> | <code>ansible all -m apt -a upgrade=full --become --ask-become-pass</code> Upgrade all packages</br> | ||
<code>ansible all -m apt -a upgrade=dist --become --ask-become-pass</code> Full distribution upgrade, some say this may be dangerous</br> | |||
Latest revision as of 16:38, 3 September 2025
Running ad-hoc commands
ansible all --key-file <path to key-file> -i <inventory> -m <module>
Ansible config
ansible-config init --disabled > ansible.cfg Generate a commented-out sample 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
ansible all -m apt -a upgrade=dist --become --ask-become-pass Full distribution upgrade, some say this may be dangerous