Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新代码 #543

Merged
merged 19 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ remove_old_backups() {
# 函数:拉取最新代码
clone_latest_code() {
echo "拉取最新代码..."
# 进入 /data 目录
cd $DATA_DIR
git clone $REPO_URL -b $BRANCH
if [ $? -eq 0 ]; then
echo "拉取最新代码完成。"
Expand Down Expand Up @@ -201,7 +203,7 @@ crontab -e

*/10 * * * * /opt/cron/git-down-pages.sh >> /opt/cron/git-down.log 2>&1
```

**添加 NGINX 配置:**

```nginx
Expand Down
87 changes: 44 additions & 43 deletions docs/ansible.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ $ ansible target -m copy -a "src=/tmp/seq dest=/tmp/seq"
### Ansible 命令帮助
<!--rehype:wrap-class=col-span-2 row-span-3-->

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

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

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

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

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

### Ansible Galaxy 工具

Expand Down Expand Up @@ -233,40 +236,6 @@ $ ansible-galaxy init --offline <ROLE>
```
<!--rehype:className=wrap-text-->



### ansible常用模块

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

```bash
$ ansible-doc --list #查询所有模块
$ ansible <host-pattern> [options] # 标准使用方式
```

---
| :- | - | - |
| ---------------- | ------------------------------------------------ | ------------------------------------------------------------ |
| ping | 检查指定节点机器是否还能连通 | `ansible all -m ping` |
| command | 用于在各受控端节点运行指定的命令 | `ansible all -m command -a 'hostname'` |
| shell | shell模块可以特殊字符,而command是不支持 | `ansible all -m shell -a 'hostname && date'` |
| hostname | 修改远程受控节点的主机名的模块 | `ansible -i /opt/hosts xx -m hostname -a 'name=ansible-client-199'` |
| copy | 在远程主机执行复制操作文件 | `ansible all -m copy -a 'src=/etc/hosts dest=/opt/hosts backup=yes'` |
| fetch | 从远程主机获取文件到管理节点,但是不支持目录操作 | `ansible all -m fetch -a "src=/etc/yum.repos.d/epel.repo dest=/usr/local/src"` |
| script | 管理端一个脚本,然后在远程服务器上执行 | `ansible all -m script -a '/root/time.sh'` |
| file | 主要用于远程主机上的文件和目录操作 | `ansible all -m file -a "path=/root/rsync.password mode=600 state=touch"` |
| cron | 管理执行任务计划模块(增删改查) | `ansible all -m cron -a "name='test a job' user=root job='/bin/sh /server/scripts/test.sh'` minute=* hour=* day=* month=* weekday=*" |
| 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"` |
| service和systemd | 用于管理远程主机的服务 | `ansible all -m systemd -a "name=httpd state=started enabled=yes"<br />ansible all -m systemd -a "name=httpd state=restarted"` |
| user | useradd, userdel, usermod | `ansible all -m user -a 'name=haha remove=no state=absent'` |
| group | groupadd, groupdel, groupmod | `ansible all -m group -a 'name=mygroup state=absent'` |
| setup | 可收集远程主机的facts变量的信息 | `ansible all -m setup -a 'filter=ansible_default_ipv4'` |
| 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"` |
| replace | 和 sed 命令比较类似,用于正则匹配和替换 | `ansible all -m replace -a "path=/etc/fstab regexp=^(UUID.*) replace='#\1'"` |
| lineinfile | 正则匹配,更改某个关键参数值 | `ansible all -m lineinfile -a "path=/etc/selinux/config regexp='^SELINUX=' line='SELINUX=disabled'" |



### ansible-doc

在本地访问文档
Expand Down Expand Up @@ -443,6 +412,38 @@ $ ansible-pull -U <repository> [options]
<!-- ### ansible-playbook -->
<!-- todo -->

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

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

```bash
$ ansible-doc --list #查询所有模块
$ ansible <host-pattern> [options] # 标准使用方式
```

---
| :- | - | - |
| ---------------- | ------------------------------------------------ | ------------------------------------------------------------ |
| ping | 检查指定节点机器是否还能连通 | `ansible all -m ping` |
| command | 用于在各受控端节点运行指定的命令 | `ansible all -m command -a 'hostname'` |
| shell | shell模块可以特殊字符,而command是不支持 | `ansible all -m shell -a 'hostname && date'` |
| hostname | 修改远程受控节点的主机名的模块 | `ansible -i /opt/hosts xx -m hostname -a 'name=ansible-client-199'` |
| copy | 在远程主机执行复制操作文件 | `ansible all -m copy -a 'src=/etc/hosts dest=/opt/hosts backup=yes'` |
| fetch | 从远程主机获取文件到管理节点,但是不支持目录操作 | `ansible all -m fetch -a "src=/etc/yum.repos.d/epel.repo dest=/usr/local/src"` |
| script | 管理端一个脚本,然后在远程服务器上执行 | `ansible all -m script -a '/root/time.sh'` |
| file | 主要用于远程主机上的文件和目录操作 | `ansible all -m file -a "path=/root/rsync.password mode=600 state=touch"` |
| cron | 管理执行任务计划模块(增删改查) | `ansible all -m cron -a "name='test a job' user=root job='/bin/sh /server/scripts/test.sh' minute=* hour=* day=* month=* weekday=*"` |
| 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"` |
| `service`和`systemd` | 用于管理远程主机的服务 | `ansible all -m systemd -a "name=httpd state=started enabled=yes"`<br />`ansible all -m systemd -a "name=httpd state=restarted"` |
| user | useradd, userdel, usermod | `ansible all -m user -a 'name=haha remove=no state=absent'` |
| group | groupadd, groupdel, groupmod | `ansible all -m group -a 'name=mygroup state=absent'` |
| setup | 可收集远程主机的facts变量的信息 | `ansible all -m setup -a 'filter=ansible_default_ipv4'` |
| 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"` |
| replace | 和 sed 命令比较类似,用于正则匹配和替换 | `ansible all -m replace -a "path=/etc/fstab regexp=^(UUID.*) replace='#\1'"` |
| lineinfile | 正则匹配,更改某个关键参数值 | `ansible all -m lineinfile -a "path=/etc/selinux/config regexp='^SELINUX=' line='SELINUX=disabled'"` |
<!--rehype:className=left-align-->

另见
---

Expand Down