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

    run ls command on all computes nodes

    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

    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