For the examples we consider the following hosts file:

    node1 ansible_host=
    node2 ansible_host=
    node3 ansible_host=

    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'


    • -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'


    • --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


    Run a playbook locally

    ansible-playbook --connection=local --inventory, --limit playbook.yml -i ansible_hosts

    Passing variables through cli

    --extra-vars "version=1.23.45 other_variable=foo"