Docs/Ansible/Ansible基础.md
2022-10-18 16:59:37 +08:00

54 lines
984 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### 配置文件
```
/etc/ansible/ansible.cfg ## 主配置文件
/etc/ansible/hosts ## 主机清单
/etc/ansible/roles/ ## 角色目录
```
### 列出ansible模块
```
ansible-doc -l
```
#### 查看模块帮助文档
```
ansible-doc ping # 查看ping模块的帮助文档详细
ansible-doc -s ping # 查看ping模块的帮助文档简略
```
## 命令格式
```
ansible <host-pattern> [-m moudule_name] [-a args]
```
#### 查看主机列表中的主机
```
ansible <host-pattern> --list-hosts
```
#### 提示输入密码
```
-k或--key-pass
```
#### 执行操作的用户
```
-u或--user=REMOTE-USER
```
#### 逻辑与
```
ansible "webserver:&dbserver" -m ping ## 执行操作的主机在两个主机组中都存在
```
#### 逻辑非
```
ansible 'webserver:!dbserver' -m ping ## 执行操作的主机在webserver组中但不在dbserver中
```
### ansible-vault
```
ansible-vault encrypt xxx.yaml ## 加密
ansible-vault decrypt xxx.yaml ## 解密
```