Skip to content
On this page

Ansible 清单管理

[test1]
A[1:4].agou-ops.top ansible_ssh_pass='suofeiya'
[test2]
B.agou-ops.top

[test:children]
test1
test2

# 或者
[test]
test[1:4].agou-ops.top
[test:vars]
ansible_ssh_pass='suofeiya'
# yaml语法如下
all:
  hosts:
    10.1.1.61:
  children:
    test1:
      hosts:
        10.1.1.60:
    test2:
      hosts:
        10.1.1.70:
# 对应ini格式
10.1.1.61

[test1]
10.1.1.60

[test2]
10.1.1.70
[test1]
A[1:4].agou-ops.top ansible_ssh_pass='suofeiya'
[test2]
B.agou-ops.top

[test:children]
test1
test2

# 或者
[test]
test[1:4].agou-ops.top
[test:vars]
ansible_ssh_pass='suofeiya'
# yaml语法如下
all:
  hosts:
    10.1.1.61:
  children:
    test1:
      hosts:
        10.1.1.60:
    test2:
      hosts:
        10.1.1.70:
# 对应ini格式
10.1.1.61

[test1]
10.1.1.60

[test2]
10.1.1.70

附录: Ansible 内置变量

参数用途例子
ansible_ssh_host定义hosts ssh地址ansible_ssh_host=192.168.6.240
ansible_ssh_port定义hosts ssh端口ansible_ssh_port=52113
ansible_ssh_user定义hosts ssh认证用户ansible_ssh_user=user
ansible_ssh_pass定义hosts ssh认证密码ansible_ssh_pass=pass
ansible_sudo定义hosts sudo用户ansible_sudo=www
ansible_sudo_pass定义hosts sudo密码ansible_sudo_pass=pass
ansible_sudo_exe定义hosts sudo路径ansible_sudo_exe=/usr/bin/sudo
ansible_connection定义hosts 连接方式ansible_connection=local
ansible_ssh_private_key_file定义hosts 私钥ansible_ssh_private_key_file=/root/key
ansible_ssh_shell_type定义hosts shell类型ansible_ssh_shell_type=bash
ansible_python_interpreter定义hosts 任务执行python路径ansible_python_interpreter=/usr/bin/python2.7
ansible_*_interpreter定义hosts 其他语言解析路径ansible_*_interpreter=/usr/bin/ruby