Ansible
For the examples we consider the following hosts
file:
[controllers]
node1 ansible_host=10.0.1.214
[computes]
node2 ansible_host=10.0.3.140
node3 ansible_host=10.0.0.200
Run a command on specific hosts (no python required)
run ls command on all computes that are part of nodes
group.
ansible -i hosts computes -m raw -a 'ls'
Note:
-m
choose the module name, raw allow to run any command-a
for arguments to the module- raw module does not require python on target nodes
Restart a service
ansible -i hosts -m service -a "name=slurmd state=restarted" computes
Reboot all nodes
ansible --become --user ubuntu -i environments/prod1/hosts all --module-name raw -a 'reboot'
Notes:
--become
is equivalent to run a sudo--user ubuntu
will connect with the ubuntu user
Gather variables from the nodes
ansible -m setup -a gather_subset='network' -i hosts node2
Note: network
can be changed by all
to get all informations.
Avoid to check the host key
export ANSIBLE_HOST_KEY_CHECKING=False
Run a playbook locally
ansible-playbook --connection=local --inventory 127.0.0.1, --limit 127.0.0.1 playbook.yml -i ansible_hosts
Passing variables through cli
--extra-vars "version=1.23.45 other_variable=foo"