/etc/ansible/hosts

Source: Internet
Author: User
Tags aliases ssh ssh port

For example

[Test]

Web.yinzhipeng.com

DHCP ansible_ssh_host=172.16.18.195

1. The name in brackets indicates the group name

2. The host (hosts) section can use the domain name, hostname, IP address, of course, the use of the first two, the host can also be resolved to the corresponding IP address, generally such configuration more use of IP address;

3. Aliases, such as the DHCP line

If some hosts have SSH running on a custom port, you can write this on the list

192.168.1.1:3091

If you want to set some aliases for some static IP, you can do this:

Server1 Ansible_ssh_port = 1055 Ansible_ssh_host = 172.16.3.2

The Server1 alias above refers to the host with IP 172.16.3.2,ssh connection port 1055.



Specify host Scope

[Webservers]

www[01:50].jintian.com

[Databases]

db-[a:f].jintian.com

The above specifies a total of 50 hosts from the Web1 to the Web50,webservers group, and the databases group has db-a to db-f a total of 6 hosts.


Here are the parameters that can be used in the hosts

Ansible_ssh_host

#用于指定被管理的主机的真实IP

Ansible_ssh_port

#用于指定连接到被管理主机的ssh端口号, the default is

Ansible_ssh_user

#ssh连接时默认使用的用户名

Ansible_ssh_pass

#ssh连接时的密码

Ansible_sudo_pass

#使用sudo连接用户时的密码

ansible_sudo_exec

#如果sudo命令不在默认路径, you need to specify the sudo command path ansible_ssh_private_key_file

#秘钥文件路径, key file This option is available if you do not want to use Ssh-agent management Ansible_shell_type

#目标系统的shell的类型, the default SH

ansible_connection

type of #SSH connection: local, SSH, Paramiko, default is Paramiko before Ansible 1.2, later smart selection, preference for controlpersist based SSH (support prerequisites)

Ansible_python_interpreter

#用来指定python解释器的路径, the default is/usr/bin/python you can also specify the path of Ruby, Perl

Ansible_*_interpreter

#其他解释器路径, usage is similar to Ansible_python_interpreter, where "*" can be in other languages such as Ruby or Perl


[Test]

192.168.1.1 ansible_ssh_user=root ansible_ssh_pass= ' P@ssw0rd ' 192.168.1.2 ansible_ssh_user=breeze ansible_ssh_ pass= ' 123456 ' 192.168.1.3 ansible_ssh_user=bernie ansible_ssh_port=3055 ansible_ssh_pass= ' 456789 '

The above example specifies three hosts, three hosts with the password is P@ssw0rd, 123456, 45789, the specified SSH connection user name is root, Breeze, bernie,ssh Port respectively is 22, 22, 3055, This way, when the ansible command executes, it is no longer necessary to instruct the user and password.


indicates that all hosts can use all or *

in Ansible and Ansible-playbook, you can also explicitly specify to exclude certain hosts or groups by using a parameter of "--limit":

Ansible-playbook site.yml--limit Datacenter2
starting with Ansible1.2, if you want to exclude a host in a file, you can use "@":

Ansible-playbook site.yml--limit @retry_hosts. txt


View Ansible version can be used

ansible--version View



article excerpt from http://breezey.blog.51cto.com/2400275/1757643


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.