## inventory
inventor是描述主機的文件。
**localhost**會被ansible自動添加到inventory中,代表本機。
>[info] 在執行的時候會通過本機而不是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
~~~
## 群組的與或非
~~~yaml
webservers:&staging 與
webservers:staging 或
webservers:!staging 非
~~~
- 目錄
- ansible基礎
- ansible簡介
- ansible安裝和測試
- ansible配置文件
- 常用命令
- yaml在ansible中的用法
- inventory
- 變量與facts
- when語句
- handler模塊
- 大雜燴
- ansible模塊
- assert 模塊
- copy模塊
- cron模塊
- debug模塊
- django_manage模塊
- file模塊
- filesystem模塊
- git模塊
- hostname模塊
- lineinfile模塊
- mount模塊
- mysql_user模塊
- mysql_db模塊
- pip模塊
- selinux
- setup模塊
- shell 和 command 模塊
- stat模塊
- supervisorctl
- systemd
- timezone
- unarchive模塊
- user模塊
- wait_for
- yum和service模塊
- 其他模塊或者方法
- setup模塊
- url模塊
- slack 模塊
- pause 模塊
- 其他
- 報錯處理
- playbooks
- 復雜的playbook
- 循環
- roles
- YAML
- jinja2