Skip to content

Commit 8ef5df7

Browse files
committed
doc: update docs/ansible.md jaywcjlove#535
1 parent 704ba73 commit 8ef5df7

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

docs/ansible.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ $ ansible target -m copy -a "src=/tmp/seq dest=/tmp/seq"
140140
### Ansible 命令帮助
141141
<!--rehype:wrap-class=col-span-2 row-span-3-->
142142

143-
```bash
143+
```shell
144144
$ ansible
145145
$ ansible <host-pattern> [options]
146146
```
@@ -171,6 +171,7 @@ $ ansible <host-pattern> [options]
171171
`--vault-password-file=VAULT_PASSWORD_FILE` | 保险库密码文件
172172
`-v`, `--verbose` | 详细模式(-vvv 更多,-vvvv 启用连接调试)
173173
`--version` | 显示程序的版本号并退出
174+
<!--rehype:className=left-align-->
174175

175176
控制谁以及如何连接到主机,连接选项:
176177

@@ -182,24 +183,26 @@ $ ansible <host-pattern> [options]
182183
`-c CONNECTION`, `--connection=CONNECTION` | 要使用的连接类型 (default=smart)
183184
`-T TIMEOUT`, `--timeout=TIMEOUT` | 以秒为单位覆盖连接超时 (default=10)
184185
`--ssh-common-args=SSH_COMMON_ARGS` | 指定要传递给 sftp/scp/ssh 的常用参数 (e.g. ProxyCommand)
185-
`--sftp-extra-args=SFTP_EXTRA_ARGS` | 指定仅传递给 sftp 的额外参数 (e.g. -f, -l)
186+
`--sftp-extra-args=SFTP_EXTRA_ARGS` | 指定仅传递给 `sftp` 的额外参数 (e.g. -f, -l)
186187
`--scp-extra-args=SCP_EXTRA_ARGS` | 指定仅传递给 `scp` 的额外参数 (e.g. -l)
187188
`--ssh-extra-args=SSH_EXTRA_ARGS` | 指定仅传递给 `ssh` 的额外参数 (e.g. -R)
189+
<!--rehype:className=left-align-->
188190

189191
控制您成为目标主机上的用户的方式和用户,特权升级选项:
190192

191193
:- | -
192194
:- | -
193-
`-s`, `--sudo` | 使用 sudo (nopasswd) 运行操作(已弃用,使用 become)
194-
`-U SUDO_USER`, `--sudo-user=SUDO_USER` | 所需的 sudo 用户(默认=root)(已弃用,使用 become)
195-
`-S`, `--su` | 使用 su 运行操作(已弃用,使用 become)
196-
`-R SU_USER`, `--su-user=SU_USER` | 以该用户身份使用 su 运行操作(默认 = root)(已弃用,使用 become)
195+
~~`-s`~~, ~~`--sudo`~~ | 使用 sudo (nopasswd) 运行操作(已弃用,使用 become)
196+
~~`-U SUDO_USER`~~, ~~`--sudo-user=SUDO_USER`~~ | 所需的 sudo 用户(默认=root)(已弃用,使用 become)
197+
~~`-S`~~, ~~`--su`~~ | 使用 su 运行操作(已弃用,使用 become)
198+
~~`-R SU_USER`~~, ~~`--su-user=SU_USER`~~ | 以该用户身份使用 su 运行操作(默认 = root)(已弃用,使用 become)
197199
`-b`, `--become` | 使用 become 运行操作(不暗示密码提示)
198-
`--become-method=BECOME_METHOD` | 要使用的权限提升方法(默认=sudo),有效选择:[ sudo | su | pbrun | pfexec | runas | doas | dzdo ]
200+
`--become-method=BECOME_METHOD` | 要使用的权限提升方法(默认=sudo),有效选择:\[ `sudo` \| `su` \| `pbrun` \| `pfexec` \| `runas` \| `doas` \| `dzdo` \]
199201
`--become-user=BECOME_USER` | 以该用户身份运行操作(默认=root)
200-
`--ask-sudo-pass` | 询问 sudo 密码(已弃用,使用 become)
201-
`--ask-su-pass` | 询问 su 密码(已弃用,使用 become)
202+
~~`--ask-sudo-pass`~~ | 询问 sudo 密码(已弃用,使用 become)
203+
~~`--ask-su-pass`~~ | 询问 su 密码(已弃用,使用 become)
202204
`-K`, `--ask-become-pass` | 要求提权密码
205+
<!--rehype:className=left-align-->
203206

204207
### Ansible Galaxy 工具
205208

@@ -233,8 +236,6 @@ $ ansible-galaxy init --offline <ROLE>
233236
```
234237
<!--rehype:className=wrap-text-->
235238

236-
237-
238239
### ansible-doc
239240

240241
在本地访问文档
@@ -412,8 +413,9 @@ $ ansible-pull -U <repository> [options]
412413
<!-- todo -->
413414

414415
### ansible常用模块
416+
<!--rehype:wrap-class=col-span-3 -->
415417

416-
ansible的模块已经高达3000+之多。但是个人在日常工作中,比较常见的大约20多个
418+
`Ansible` 的模块已经高达 `3000+` 之多。但是个人在日常工作中,比较常见的大约 `20` 多个
417419

418420
```bash
419421
$ ansible-doc --list #查询所有模块
@@ -432,14 +434,15 @@ $ ansible <host-pattern> [options] # 标准使用方式
432434
| script | 管理端一个脚本,然后在远程服务器上执行 | `ansible all -m script -a '/root/time.sh'` |
433435
| file | 主要用于远程主机上的文件和目录操作 | `ansible all -m file -a "path=/root/rsync.password mode=600 state=touch"` |
434436
| cron | 管理执行任务计划模块(增删改查) | `ansible all -m cron -a "name='test a job' user=root job='/bin/sh /server/scripts/test.sh' minute=* hour=* day=* month=* weekday=*"` |
435-
| yum | RedHat和CentOS的软件包安装和管理 | `安装<br />ansible all -m yum -a "name=httpd state=present"<br/>ansible all -m yum -a "name=httpd state=installed"<br />卸载<br />ansible all -m yum -a "name=httpd state=absent"<br/>ansible all -m yum -a "name=httpd state=removed"` |
436-
| service和systemd | 用于管理远程主机的服务 | `ansible all -m systemd -a "name=httpd state=started enabled=yes"<br />ansible all -m systemd -a "name=httpd state=restarted"` |
437+
| yum | RedHat和CentOS的软件包安装和管理 | 安装<br />`ansible all -m yum -a "name=httpd state=present"`<br/>`ansible all -m yum -a "name=httpd state=installed"`<br />卸载<br />`ansible all -m yum -a "name=httpd state=absent"`<br/>`ansible all -m yum -a "name=httpd state=removed"` |
438+
| `service``systemd` | 用于管理远程主机的服务 | `ansible all -m systemd -a "name=httpd state=started enabled=yes"`<br />`ansible all -m systemd -a "name=httpd state=restarted"` |
437439
| user | useradd, userdel, usermod | `ansible all -m user -a 'name=haha remove=no state=absent'` |
438440
| group | groupadd, groupdel, groupmod | `ansible all -m group -a 'name=mygroup state=absent'` |
439441
| setup | 可收集远程主机的facts变量的信息 | `ansible all -m setup -a 'filter=ansible_default_ipv4'` |
440442
| authorized_key | 为特定的用户账号添加或删除 SSH authorized keys | `ansible all -m authorized_key -a "user=root key='{{lookup('file','/root/.ssh/id_rsa.pub')}}' path=/root/.ssh/authorized_keys manage_dir=no"` |
441443
| replace | 和 sed 命令比较类似,用于正则匹配和替换 | `ansible all -m replace -a "path=/etc/fstab regexp=^(UUID.*) replace='#\1'"` |
442444
| lineinfile | 正则匹配,更改某个关键参数值 | `ansible all -m lineinfile -a "path=/etc/selinux/config regexp='^SELINUX=' line='SELINUX=disabled'"` |
445+
<!--rehype:className=left-align-->
443446

444447
另见
445448
---

0 commit comments

Comments
 (0)