ansible的常见使用方法

  • A+
所属分类:ansible

Inventory:

    inventory是命名主机的集合,文件为/etc/ansible/hosts

    范例1:(可解析的主机名或者IP)

    

 blue.example.com
 192.168.100.1

    范例2:(主机群的集合)

 [webservers]
alpha.example.org
beta.example.org
192.168.1.100
192.168.1.110

    范例3:(连续的段)

 www[001:006].example.com

    范例4:(定义多级

[mysql:children]    #多级组  组名mysql
mysql_master
mysql_slave
mysql_proxy
[mysql_master]
192.168.80.100
[mysql_slave]
192.168.80.101
[mysql_proxy]
192.168.80.200

    范例5:定义变量

172.26.1.169 ansible_ssh_user=text      设置远程主机,远程管理主机账号
常见还有:
ansible_ssh_port=22       远程主机端口
ansible_ssh_host             指定被管理主机
ansible_ssh_private_key_file   指定KEY文件
host_key_checking=False  当第一次远程连接主机时,跳过yes和no

ansible命令的用法

    Usage: ansible <host-pattern> [options]

        范例:ansible all -m command -a 'ifconfig'  

           说明:all 表示inventory定义的主机或者群集,可以是IP,all代表所有主机

                    -m:指定模块,不指定默认是command

                    -a:模块参数

        其中常见模块的介绍下一篇blog专门介绍

ansible-doc的常见用法:

            -l:查询ansible的所有模块

            -s 模块名:查询模块的具体用法

                范例:ansible-doc -s user  查询user模块的用法

ansible-playbook:定义播放档(个人理解),让自动化执行

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
admin

发表评论

您必须登录才能发表评论!