其他分享
首页 > 其他分享> > 1,ansible1

1,ansible1

作者:互联网

开启免交互:
[root@es1 ansible]# cat ansible.cfg |grep host_key_check
host_key_checking = False
[root@es1 ansible]# 

默认模块是: -m command

查看帮助文档:ansible-doc

定义变量方式一(主机变量):
[root@es1 ansible]# cat hosts
[webservers]
192.168.0.12 ansible_ssh_user=root ansible_ssh_pass=123456  http_port=123
192.168.0.13 ansible_ssh_user=root ansible_ssh_pass=123456  http_port=123

[root@es1 ansible]# ansible webservers -a 'echo {{ http_port }}'
192.168.0.13 | CHANGED | rc=0 >>
123
192.168.0.12 | CHANGED | rc=0 >>
123
[root@es1 ansible]# 



定义变量方式二(组变量,可见主机变量的优先级更高):
[root@es1 ansible]# cat hosts
[webservers]
192.168.0.12 ansible_ssh_user=root ansible_ssh_pass=123456  http_port=123
192.168.0.13 ansible_ssh_user=root ansible_ssh_pass=123456  http_port=123

[webservers:vars]
http_port=80
[root@es1 ansible]# 
[root@es1 ansible]# ansible webservers -a 'echo {{ http_port }}'
192.168.0.12 | CHANGED | rc=0 >>
123
192.168.0.13 | CHANGED | rc=0 >>
123
[root@es1 ansible]# 


定义变量方式三(创建变量目录)
[root@es1 group_vars]# mkdir /etc/ansible/group_vars
[root@es1 group_vars]# touch webservers.yml
[root@es1 group_vars]# cat ../hosts 
[webservers]
192.168.0.12 ansible_ssh_user=root ansible_ssh_pass=123456  http_port=123
192.168.0.13 ansible_ssh_user=root ansible_ssh_pass=123456  http_port=123

[root@es1 group_vars]# 
[root@es1 group_vars]# cat webservers.yml 
http_port: 8080
server_name: www
[root@es1 group_vars]# 
[root@es1 group_vars]# 
[root@es1 group_vars]# ansible all -a 'echo {{ server_name }}'
192.168.0.12 | CHANGED | rc=0 >>
www
192.168.0.13 | CHANGED | rc=0 >>
www
[root@es1 group_vars]# 

  

标签:ansible1,es1,vars,192.168,ansible,ssh,root
来源: https://www.cnblogs.com/k8s-pod/p/13928908.html