Difference between revisions of "Ansible"

From 6bit.ch wiki
Jump to navigation Jump to search
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>


== Example ansible config ==
== Ansible Config ==
<code>ansible-config init --disabled > ansible.cfg</code> Generate a commented-out sample config</br>
<code>ansible-config init --disabled > ansible.cfg</code> Generate a commented-out sample config</br>



Revision as of 16:37, 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