Notes about Ansible

From Luis Gallego Hurtado - Not Another IT guy
Jump to: navigation, search

Useful Ansible commands

  • Avoid to input the ssh passphrase more than once
eval 'ssh-agent' 
ssh-add <PATH_TO_ID_RSA_FILE, e.g. ~/.ssh/id_rsa>
  • Install a role with ansible-galaxy
ansible-galaxy install <ROLE_NAME> --roles-path <PATH_TO_ROLES_DIR>
  • Perform a ping to a given IP
ansible all -i '<IP>,' -c local -m ping
  • Perform a ping to a host in host file
  • Display all Ansible variables (it uses ssh connection)
ansible -i <PATH_TO_INVENTORY_HOST_FILE> -m setup <HOST>
  • Run an Ansible playbook
ansible-playbook -i <PATH_TO_INVENTORY_HOST_FILE> --extra-vars="<EXTRA_VARIABLES, e.g. host=elasticsearchsinglenodecluster>" <PATH_TO_PLAYBOOK_YML_FILE> -vvvvvv