Install
- centos
yum install epel-release -y && yum install ansible -y && ansible --verson
Inventory
example:
[kvm]
192.168.0.51 ansible_port=2222
192.168.0.52 #ansible_port=22222
192.168.0.53 #ansible_port=22222
192.168.0.54 #ansible_port=22222
[kvm:vars]
ansible_user=root
ansible_port=22222
Here are some commonly used SSH variables in Ansible:
* ansible_user: Specifies the SSH user to use when connecting to remote hosts.
* ansible_port: Specifies the SSH port to use when connecting to remote hosts. The default is port 22.
* ansible_private_key_file**: Specifies the path to the private key file to use for SSH authentication.
* ansible_ssh_common_args: Specifies additional SSH command-line arguments to pass to the SSH client.
* ansible_ssh_extra_args: Specifies extra SSH command-line arguments to pass to the SSH client.
* ansible_ssh_timeout: Specifies the SSH connection timeout in seconds.
Note:
when special the group variables, you can also special it in host variables.
Synopsis
# ansible kvm -m shell -a "virsh list --all"
# common options
--list-hosts
outputs a list of matching hosts; does not execute anything else
-i 'file_path'
specify inventory host path (default=/etc/ansible/hosts)
-m 'MODULE_NAME'
module name to execute (default=command)
-f 'FORKS'
specify number of parallel processes to use (default=5)
Note
The "command" module works without a shell by executing the command directly on the remote hosts. So you can use it to excute some simple tasks.