ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# inventory ## inventory inventor是描述主机的文件。 **localhost**会被ansible自动添加到inventory中,代表本机。 > 在执行的时候会通过本机而不是SSH。 ## inventory行为参数 ``` 名称 默认值 描述 ------------------------------------------------------------------------ ansible_ssh_host none 主机的名字 ansible_ssh_port 22 ssh端口 ansible_ssh_user root ssh登录使用的用户名 ansible_ssh_pass none ssh认证使用的密码 ansible_ssh_private_key_file none ssh认证使用的私钥 ansible_connection smart Ansible使用何种连接模式 ansible_shell_type /bin/sh 命令行所使用的shell ansible_python_type /usr/bin/python 命令行所使用的shell ``` ### 改变行为参数的默认值 ``` invetory行为参数 ansible.cfg选项 ------------------------------------------------- ansible_ssh_port remote_port ansible_ssh_user remote_user ansible_ssh_private_key_file private_key_file ansible_shell_type executable ansible_python_type /usr/bin/python ``` ## 群组 ansible自动定义了一个群组叫“all”,包括in ventory中的所有主机。 ### 群组嵌套 注意这里的**children** ``` [django:children] web task ``` ## 主机变量 在inventory中定义主机时,同时定义的变量 ``` vagrant1 ansible_ssh_port=222 ``` ### 别名和端口 ``` 127.0.0.1:2222 128.192.168.1.12:2222 ``` ## 组内变量 在inventory中定义`主机组`时,同时定义的变量 ``` [all:vars] ntp_sever=cn.ntp.pool.org [productions:vars] db_user=mysql db_password=mysql@123 ``` ## 群组的与或非 ``` webservers:&staging 与 webservers:staging 或 webservers:!staging 非 ```