Ansible ad hoc command examples
command
ansible group001 -i hosts.ip -m shell -a "run some shell command" --become -f 1 -v
inventory demo
[demo:children]
nginx
mysql
[nginx]
192.168.100.101 ansible_ssh_user=ubuntu ansible_ssh_port=22 ansible_python_interpreter=/usr/bin/python3
[mysql]
192.168.100.102 ansible_ssh_user=ubuntu ansible_ssh_port=22 ansible_python_interpreter=/usr/bin/python3
ansible.cfg demo
[defaults]
private_key_file = ~/.ssh/id_rsa
host_key_checking = False
forks = 300
timeout = 40
deprecation_warnings = False
roles_path = ansible/roles
inventory_plugins = ansible/plugins/inventory
allow_world_readable_tmpfiles=true
[ssh_connection]
ssh_args = -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=600s -o StrictHostKeyChecking=no
retries = 5
pipelining = True
control_path = /tmp/ansible-ssh-%%h-%%p-%%r
reference
https://docs.ansible.com/ansible/latest/index.html
Disclaimer
- License under
CC BY-NC 4.0
- Copyright issue feedback
me#imzye.me
, replace # with @ - Not all the commands and scripts are tested in production environment, use at your own risk
- No privacy information is collected here
Try iOS App