内置插件
27 个内置插件与 3 个编排指令的完整参考。
FleetKite 内置 27 个插件 与 3 个编排指令(与 fleetkite plugins list 输出一致)。
本页的参数表由引擎自身导出,因此不会与实际注册的参数产生偏差;任何时候都可以用 fleetkite plugins show <名称> 拿到同样的信息。
能力与行为速查表
| 名称 | 分类 | --check 预演 | --diff | connection: local | become 提权 | 典型 register 返回字段 |
|---|---|---|---|---|---|---|
include_tasks | 编排指令 | 继承子任务行为 | 取决于子任务 | 支持 | 继承到子任务 | — |
include_vars | 编排指令 | 继承 / 正常加载 | — | 支持 | — | — |
include_role | 编排指令 | 继承子任务行为 | 取决于子任务 | 支持 | 继承到子任务 | — |
shell | 命令执行 | 跳过 | — | 支持 | 支持 | stdout, stdout_lines, rc |
async_status | 异步查询 | 支持(只读) | — | 仅 SSH | — | fleetkite_job_id, finished, rc, stdout |
expect | 交互命令 | 跳过 | — | 仅 SSH | 支持 | command, output(失败时 error) |
setup | 事实采集 | 支持(只读) | — | 支持 | — | fleetkite_* 全部主机事实 |
set_fact | 变量注册 | 支持 | — | 支持 | — | set_facts, cacheable |
debug | 调试输出 | 支持 | — | 支持 | — | msg / var, value / variables |
assert | 断言校验 | 支持 | — | 支持 | — | msg, evaluated, successful(失败时 failed, failed_messages) |
fail | 主动失败 | 支持 | — | 支持 | — | msg |
file | 路径管理 | 支持 | — | 支持 | 支持 | status, msg |
stat | 文件元数据 | 支持(只读) | — | 支持 | — | exists, path, size, perms, user, group, mtime, isdir, isreg, checksum, md5 |
lineinfile | 文本行编辑 | 支持 | 支持 | 支持 | 支持 | diff(开启 --diff 时) |
transfer_file | SFTP 传输 | 支持 | 支持 | 仅 SSH | 支持 | diff(文本单文件 --diff 时) |
template | 模板渲染 | 支持 | 支持 | 支持 | 支持 | diff(开启 --diff 时) |
unarchive | 归档解压 | 支持 | — | 支持 | 支持 | src, dest |
get_url | 远端下载 | 支持 | — | 支持 | 支持 | url, dest |
http | HTTP 请求 | 仅放行只读方法 | — | 支持 | — | status_code(可选 json, content) |
wait_for | 端口 / 文件等待 | 支持(只读) | — | 支持(仅文件) | — | status, msg |
user | Linux 用户 | 跳过 | — | 仅 SSH | 支持 | stdout |
cron | 计划任务 | 支持 | — | 仅 SSH | 支持 | status, msg |
apt | Debian 软件包 | 支持 | — | 仅 SSH | 支持 | status, msg |
yum / dnf | RedHat 软件包 | 支持 | — | 仅 SSH | 支持 | status, msg |
service | 通用服务 | 支持 | — | 仅 SSH | 支持 | status, msg |
systemd | Systemd 单元 | 跳过 | — | 仅 SSH | 不支持(需直连特权用户) | status, msg |
git | Git 仓库 | 跳过 | — | 仅 SSH | — | status, msg |
docker / podman | 容器管理 | 跳过 | — | 仅 SSH | — | status, msg |
插件详情
include_tasks
运行到达该步骤时从本地读取一个 YAML 任务列表文件并按顺序展开执行。validate / inspect 对主剧本离线校验时仅记录声明,实际内容在运行期加载;支持继承父任务的 when(逐一评估)、tags、become*、connection、delegate_to。
在角色内优先按 当前任务目录 -> roles/<name>/tasks/ -> roles/<name>/ 查找目标文件。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
file | string | 是 | — | Task file. Relative paths are based on the current task source. |
register 输出字段:—
示例:
- name: 加载发行版专属软件安装流程
type: include_tasks
when: "fleetkite_os_family == 'Debian'"
args:
file: "tasks/debian_setup.yml"include_vars
读取 YAML 字典文件并即时合并进当前主机当前 Play 的 VariableStore(覆盖同名已有变量)。
在角色内优先按 roles/<name>/vars/ -> 当前任务目录 -> roles/<name>/ 查找。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
file | string | 是 | — | Variable file. Relative paths are based on the current task source. |
register 输出字段:—
示例:
- name: 加载对应环境配置变量
type: include_vars
args:
file: "vars/{{ app_env }}.yml"
- name: 引用刚合入的变量
type: debug
args:
msg: "Loaded API endpoint: {{ api_base_url }}"include_role
按需在任意任务位置、配合 when / loop 执行指定角色的任务文件,并将该角色的变量与 handlers 动态合入当前主机与当前 Play 队列。
vars_from 未显式指定且默认 main 不存在时跳过,显式指定不存在时报错。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
name | string | 是 | — | Role name. |
tasks_from | string | main | Task file under roles/<name>/tasks/ without requiring a .yml/.yaml suffix. | |
vars_from | string | — | Variable file under roles/<name>/vars/. | |
handlers_from | string | — | Handler file under roles/<name>/handlers/. |
register 输出字段:—
示例:
- name: 执行数据库备份子流程
type: include_role
when: "'db' in group_names_hint"
args:
name: postgres
tasks_from: backup
vars_from: prod
handlers_from: mainshell
在远程 SSH 主机执行命令,或在 connection: local 下调用本机 /bin/sh -c(Windows 下 cmd.exe)执行命令;亦内置可选交互问答对 expect_pairs。
--check 跳过;支持 connection: local、become、async / poll。命令退出码非 0 时任务状态为 failed(但仍返回以下字段),若需将非零退出码当作正常检查请配合 ignore_errors: true 或 failed_when / changed_when。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
command | string | 是 | — | Remote command. |
expect_pairs | array of objects | — | Optional interactive prompt/answer pairs using prompt and answer keys. | |
end_prompt | string | [#$]\s*$ | Completion pattern for interactive execution. |
register 输出字段:同步模式返回 rc(退出码)、stdout(标准输出与错误合并文本)、stdout_lines(按行拆分)。异步发射返回 fleetkite_job_id、pid、started、output_file;poll > 0 轮询结束后追加 finished、rc、stdout。
示例:
- name: 查询 Nginx 版本(只读不报 changed)
type: shell
changed_when: "false"
args:
command: "nginx -v 2>&1"
register: nginx_ver
- name: 校验输出内容
type: assert
args:
that:
- "nginx_ver.rc == 0"
- "'nginx/' in nginx_ver.stdout"async_status
查询之前由 shell 配 async > 0, poll: 0 启动的远端异步任务。
只读查询,支持 --check;多次查询安全,不会清理 /tmp/<jid>。被查询任务以非零退出码结束时,结果中记录真实 rc,但查询动作自身不会报错中断。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
jid | string | 是 | — | Job ID returned by an async task with poll: 0 (fleetkite_async_<nanoseconds>). |
register 输出字段:运行中返回 fleetkite_job_id、finished: false;已完成返回 fleetkite_job_id、finished: true、rc、stdout。
示例:
- name: 轮询等待异步构建完成
type: async_status
args:
jid: "{{ reindex_job.fleetkite_job_id }}"
register: job_state
until: "job_state.finished == true"
retries: 20
delay: 2expect
为带交互提示(如初始化脚本、密码确认、passwd 等)的命令提供正则匹配与自动回复(支持从 Vault 解密安全应答文本)。
--check 跳过;仅 SSH;支持 become;强烈建议涉密任务开启 no_log: true。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
command | string | 是 | — | Remote command. |
responses | object | 是 | — | Map prompt patterns to responses. |
timeout | integer | 30 | Timeout in seconds. | |
end_prompt | string | — | Completion prompt pattern. | |
chdir | string | — | Remote working directory. | |
output_var | string | — | Variable to receive output. |
register 输出字段:command(渲染后命令)、output(交互终端输出文本);失败时额外带 error。
示例:
- name: 交互式初始化测试凭证
type: expect
no_log: true
args:
command: "/usr/local/bin/init-tool.sh"
chdir: "/opt/tool"
timeout: 60
responses:
"Enter passphrase:": "{{ tool_vault_secret }}"
"Confirm \\(yes/no\\):": "yes"setup
收集受控主机操作系统、CPU、内存、挂载点、默认网卡 IPv4 及 /etc/os-release 字段并注入当前 VariableStore(fleetkite_*)。Play 默认开启 gather_facts: true 已会在阶段开始时自动执行一次;如果将 gather_facts: false 或需要刷新某项硬件变化后的状态,可显式调用。
只读,支持 --check 与 connection: local;执行成功的结果自动同步进跨 Play 事实缓存和 hostvars。
参数:
无参数。
register 输出字段:完整 fleetkite_* 键值集合(同时已自动平铺写入当前主机变量作用域,无需 register 即可直接访问 {{ fleetkite_os_family }})。
示例:
- name: 显式采集/刷新系统事实
type: setup
register: sys_factsset_fact
在任务运行期计算并设置自定义变量,供本主机后续任务使用;配合 cacheable: true 可持久化到后续 Play 与 hostvars。
支持 --check 与 connection: local。变量保留原始数据类型(数字、布尔、字符串、列表、字典),并对字符串和嵌套结构递归渲染 {{ ... }} 占位符。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
* | any | — | Each argument name becomes a variable and keeps its value type. |
register 输出字段:set_facts(写入的变量名列表)、cacheable(布尔值)。
示例:
- name: 推导日志目录并缓存主机状态
type: set_fact
args:
app_port: 8443
log_dir: "/var/log/{{ fleetkite_hostname }}"
deploy_ready: true
cacheable: truedebug
在执行输出中打印指定消息、变量路径内容(受 ***MASKED*** 保护),或在两者皆省略时打印当前全部变量快照。
支持 --check 与 connection: local;默认返回 status: ok,不计作变更。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
msg | string | — | Message. | |
var | string | — | Variable name or dotted path. | |
verbosity | integer | — | Skip the message when greater than zero. |
register 输出字段:指定 var 时返回 var、value;指定 msg 时返回 msg;均省略时返回 variables。
示例:
- name: 打印探测到的网卡主 IP
type: debug
args:
var: fleetkite_default_ipv4.addressassert
验证一条或多条 CEL 表达式是否全为真;任意一条为假即判定任务失败并终止流程(除非 ignore_errors: true 或被 rescue 捕获)。
支持 --check 与 connection: local。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
that | string or array of strings | 是 | — | One CEL expression or a list of expressions. |
success_msg | string | — | Message on success. | |
fail_msg | string | — | Message on failure. | |
quiet | boolean | — | Suppress the default success message. |
register 输出字段:成功时含 msg、evaluated(总数)、successful(通过数);失败时追加 failed(失败数)、failed_messages。
示例:
- name: 校验生产主机最低硬件规格
type: assert
args:
that:
- "fleetkite_processor_vcpus >= 2"
- "fleetkite_memtotal_mb >= 1800"
fail_msg: "主机 {{ ip }} CPU 或内存不足,无法继续部署"fail
显式抛出可控的业务报错消息(推荐通过任务级 when 控制是否触发,搭配 block / rescue 或直接熔断)。
支持 --check 与 connection: local。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
msg | string | — | Failure message. | |
when | string | — | Plugin-local condition. Prefer task-level when. |
register 输出字段:msg。
示例:
- name: 禁止在非 Linux 兼容发行版继续
type: fail
when: "fleetkite_os_family != 'Debian' && fleetkite_os_family != 'RedHat'"
args:
msg: "当前不受支持的系统家族: {{ fleetkite_os_family }}"file
幂等管理文件 / 目录存在性与权限 / 属主。
支持 --check;支持 connection: local(本机仅支持 file / directory / touch / absent 及 mode,不支持 owner / group);远程操作支持 become 提权;state: absent 删除保护 /etc 等高危根目录(但仍可递归删除常规非空子目录,请核对路径安全)。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
path | string | 是 | — | Remote filesystem path. |
state | string | file, directory, touch, absent | Desired state or operation. | |
mode | string | — | Octal mode as a quoted string, for example '0644'. | |
owner | string | — | Remote owner. | |
group | string | — | Remote group. |
register 输出字段:status、msg。
示例:
- name: 创建应用运行目录
type: file
become: true
args:
path: "/opt/demoapp/{{ item }}"
state: directory
mode: "0755"
owner: ops
group: ops
loop:
- conf
- logsstat
只读探测文件是否存在、文件类型、大小、权限、属主及 SHA-256 / MD5 哈希。
只读,支持 --check 与 connection: local。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
path | string | 是 | — | Remote filesystem path. |
get_checksum | boolean | — | Calculate SHA-256. | |
get_md5 | boolean | — | Calculate MD5. | |
follow | boolean | — | Follow symbolic links. |
register 输出字段:不存在时返回 exists: false 与 path;存在时返回 exists、path、name、size(字节)、perms、user、group、mtime、atime、isdir、isreg、islnk、ischr、isblk、isfifo、issock,开启对应选项且为常规文件时另带 checksum(SHA-256)和 / 或 md5。
示例:
- name: 检查配置文件是否存在及校验和
type: stat
args:
path: /etc/demoapp/app.conf
get_checksum: true
register: cfg_statlineinfile
幂等保障配置文件中某一行存在(支持正则匹配替换、在指定位置前 / 后插入、备份原文件)或删除匹配行。
支持 --check、--diff、connection: local 与 become(当采用 become 或 local 时采用完整文件内容快照与原子替换保证安全)。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
path | string | 是 | — | Remote filesystem path. |
line | string | — | Required when state is present. | |
regexp | string | — | Go regular expression for the target line. | |
state | string | present, absent | Desired state or operation. | |
create | boolean | — | Allow creating a missing file. | |
backup | boolean | — | Save the previous content before replacing the file. | |
insertafter | string | — | Insertion pattern or EOF. | |
insertbefore | string | — | Insertion pattern or BOF. | |
mode | string | — | Octal mode as a quoted string, for example '0644'. | |
owner | string | — | Remote owner. | |
group | string | — | Remote group. |
register 输出字段:当开启 --diff 且发生实际 / 预计变更时返回 diff。
示例:
- name: 禁用 SSH 密码登录
type: lineinfile
become: true
args:
path: /etc/ssh/sshd_config
regexp: "^#?PasswordAuthentication\\s+"
line: "PasswordAuthentication no"
backup: true
notify:
- 重载 SSH 服务transfer_file
在控制端与远端主机间安全传输文件或整个目录(内置哈希去重、原子临时文件重命名、大小上限和目录白名单校验)。
支持 --check、支持 --diff(针对单文本上传)、支持 become(通过受控提权文件存储安全写入 / 拉取);仅限 SSH 模式(不支持 connection: local)。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
local_path | string | 是 | — | Controller-side path. |
remote_path | string | 是 | — | Absolute path on the target. |
direction | string | upload, download | Desired state or operation. | |
recursive | boolean | — | Upload a workspace directory. | |
compression | string | none, gzip | Use gzip only for recursive uploads where saving bandwidth matters. | |
exclude | array of strings | — | Exclude matching names or workspace-relative paths during recursive upload. | |
mode | string | — | Octal mode as a quoted string, for example '0644'. | |
owner | string | — | Remote owner. | |
group | string | — | Remote group. |
register 输出字段:在开启 --diff 的文本单文件上传时返回 diff。
示例:
- name: 同步静态站点文件
type: transfer_file
args:
local_path: dist/web
remote_path: /var/www/demoapp
direction: upload
recursive: true
compression: gzip
exclude:
- "*.map"
- ".DS_Store"template
读取控制端模板文件,注入当前主机变量(敏感字段走内存 secureResolver)并在远端或本地原子落盘,支持内容哈希幂等比对。
支持 --check、--diff、connection: local、become。engine: gotmpl 提供 Go text/template 的完整 if / range 与 toJson / toYaml 等函数。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
src | string | 是 | — | Local template source. |
dest | string | 是 | — | Remote destination. |
mode | string | — | Octal mode as a quoted string, for example '0644'. | |
owner | string | — | Remote owner. | |
group | string | — | Remote group. | |
engine | string | default, gotmpl | Desired state or operation. | |
delimiters | array of strings | — | Custom opening and closing Go template delimiters. |
register 输出字段:在开启 --diff 且发生变更时返回 diff。
示例:
- name: 生成应用配置
type: template
become: true
args:
src: templates/app.conf.tmpl
dest: /etc/demoapp/app.conf
engine: gotmpl
delimiters: ["[[", "]]"]
mode: "0640"
notify:
- 重启 DemoAppunarchive
将控制端本地压缩包先上传(或直接读取目标机已存在的压缩包)并解压至远端目录;支持 connection: local 在控制端本机解压(支持 tar / tar.gz / tgz / tar.bz2 / tbz2 / zip,并做严密成员路径穿越 / 数量 / 总大小检查)。
支持 --check、connection: local(本地不支持 extra_opts)、become。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
src | string | 是 | — | Archive path. |
dest | string | 是 | — | Remote destination directory. |
remote_src | boolean | — | Read src on the target instead of uploading it. | |
creates | string | — | Skip when this remote path already exists. | |
extra_opts | string | — | Additional archive tool options. | |
mode | string | — | Octal mode as a quoted string, for example '0644'. | |
owner | string | — | Remote owner. | |
group | string | — | Remote group. |
register 输出字段:实际执行解压变更后包含 src、dest。
示例:
- name: 解压发布包(存在 VERSION 文件时幂等跳过)
type: unarchive
args:
src: fixtures/demoapp-pkg.tar.gz
dest: /opt/demoapp
creates: /opt/demoapp/VERSIONget_url
使用目标主机上的 curl 或 wget(connection: local 下使用 Go HTTP 客户端)下载制品文件并校验摘要。
支持 --check、connection: local、become。目标文件已存在且校验一致时直接返回 ok。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
url | string | 是 | — | HTTP or HTTPS URL. |
dest | string | 是 | — | Remote destination file. |
checksum | string | — | Expected checksum, for example sha256:<hex>. | |
force | boolean | — | Download even if the destination already exists. | |
timeout | integer | 30 | Download timeout in seconds. | |
headers | object or string | — | Map of headers or a single header line. | |
mode | string | — | Octal mode as a quoted string, for example '0644'. | |
owner | string | — | Remote owner. | |
group | string | — | Remote group. |
register 输出字段:成功变更后包含 url、dest。
示例:
- name: 下载带 SHA-256 校验的发布归档
type: get_url
args:
url: "https://releases.example.test/app-1.2.0.tar.gz"
dest: /tmp/app-1.2.0.tar.gz
checksum: "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
mode: "0644"http
进行服务健康检查,或向内部 API / Webhook 发送 HTTP 请求并结构化解析响应状态、JSON 或原始响应体。
--check 仅放行只读方法(GET / HEAD / OPTIONS),自动跳过写方法(POST / PUT / PATCH / DELETE);默认不跟随重定向;支持 connection: local(仅允许 location: control)。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
url | string | 是 | — | HTTP(S) endpoint. Do not put credentials in the URL. |
method | string | GET, HEAD, OPTIONS, POST, PUT, PATCH, DELETE | Desired state or operation. | |
location | string | control, target | Desired state or operation. | |
headers | object | — | Map from header name to string value. | |
status_code | integer or array of integers | 200 | Expected HTTP status code or list of codes. | |
timeout | integer | 10 | Request timeout in seconds. | |
body_format | string | text, json | Desired state or operation. | |
return_content | boolean | — | Expose raw response content in the registered result. | |
json_body | any | — | JSON body for a write method. |
register 输出字段:status_code(整数);满足选项时附带 json、content。
示例:
- name: 探测本地微服务就绪接口
type: http
args:
url: "http://127.0.0.1:8080/healthz"
location: target
method: GET
status_code: [200, 204]
body_format: json
return_content: true
register: api_healthwait_for
轮询检测 TCP 端口监听状态、文件出现 / 消失或文件内正则出现 / 消失(常用于服务重启后就绪等待)。
只读等待,支持 --check;connection: local 仅支持 path 文件检测(TCP 端口检测需要 SSH 连接用于建隧道)。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
host | string | — | Endpoint for TCP checks. Defaults to 127.0.0.1 from the target. | |
port | integer | — | TCP port to check. | |
path | string | — | Remote file to check. | |
state | string | started, stopped, present, absent | Desired state or operation. | |
timeout | integer | 300 | Maximum wait in seconds. | |
delay | integer | — | Initial delay in seconds. | |
search_regex | string | — | Required file content pattern. | |
exclude_regex | string | — | Forbidden file content pattern. |
register 输出字段:status、msg。
示例:
- name: 等待应用端口开放(最多等待 30 秒)
type: wait_for
args:
host: 127.0.0.1
port: 8080
state: started
delay: 1
timeout: 30user
基于目标机 useradd / usermod / userdel / chpasswd 幂等创建、更新或删除本地用户账号。
--check 跳过;仅 SSH;支持 become;管理密码时建议搭配 Vault 并开启 no_log: true。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
name | string | 是 | — | Target account name. |
state | string | present, absent | Desired state or operation. | |
uid | integer or string | — | Numeric user ID. | |
group | string | — | Primary group. | |
groups | array of strings | — | Supplementary groups. Omit to preserve existing membership. | |
shell | string | — | Login shell. | |
home | string | — | Home directory. | |
comment | string | — | Account description. | |
create_home | boolean | True | Create the home directory. | |
remove | boolean | — | Also remove the home directory when the account is removed. | |
password | string | — | Account password hash. Prefer a Vault reference. |
register 输出字段:执行修改命令时返回 stdout。
示例:
- name: 创建只读部署应用账号
type: user
become: true
args:
name: app_runner
state: present
shell: /usr/sbin/nologin
create_home: truecron
在目标用户 crontab 中创建、更新、注释禁用(disabled: true)或移除由 #FleetKite: <name> 标记管理的计划任务,绝不误删手工维护的其他行。
支持 --check;仅 SSH;支持 become。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
name | string | 是 | — | FleetKite crontab entry name. |
job | string | — | Command required when state is present. | |
minute | string | * | Cron minute. | |
hour | string | * | Cron hour. | |
day | string | * | Day of month. | |
month | string | * | Cron month. | |
weekday | string | * | Day of week. | |
user | string | — | Crontab owner. Omit for the current user. | |
state | string | present, absent | Desired state or operation. | |
disabled | boolean | — | Keep the entry commented out. |
register 输出字段:status、msg。
示例:
- name: 每天凌晨 2:30 清理临时文件
type: cron
become: true
args:
name: clean-demoapp-tmp
user: root
minute: "30"
hour: "2"
job: "/usr/bin/find /opt/demoapp/tmp -type f -mtime +7 -delete"
state: presentapt
基于 dpkg -s 幂等校验并用 apt-get 安装 / 卸载软件包(也支持传入受控机上的本地 .deb 文件路径安装)。
支持 --check;仅 SSH;支持 become。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
name | string | 是 | — | Package name. apt also accepts a local .deb path on the target. |
state | string | present, absent | Desired state or operation. | |
update_cache | boolean | — | Refresh package metadata before a change. Accepts booleans and yes/no. |
register 输出字段:status、msg。
示例:
- name: 确保 Debian/Ubuntu 主机装有 curl 与 jq
type: apt
become: true
when: "fleetkite_os_family == 'Debian'"
loop:
- curl
- jq
args:
name: "{{ item }}"
state: presentyum
基于 rpm -q 幂等检查并调用 yum 前端安装 / 移除软件。
支持 --check;仅 SSH;支持 become。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
name | string | 是 | — | Package name. |
state | string | present, absent | Desired state or operation. | |
update_cache | boolean | — | Refresh package metadata before a change. Accepts booleans and yes/no. |
register 输出字段:status、msg。
示例:
- name: 在 Rocky Linux 上安装常用基础工具
type: yum
become: true
when: "fleetkite_os_family == 'RedHat'"
args:
name: tar
state: presentdnf
基于 rpm -q 幂等检查并调用 dnf 前端安装 / 移除软件(内部同时兼容回退到 yum)。
支持 --check;仅 SSH;支持 become。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
name | string | 是 | — | Package name. apt also accepts a local .deb path on the target. |
state | string | present, absent | Desired state or operation. | |
update_cache | boolean | — | Refresh package metadata before a change. Accepts booleans and yes/no. |
register 输出字段:status、msg。
示例:
- name: 在 Rocky Linux 上安装常用基础工具
type: dnf
become: true
when: "fleetkite_os_family == 'RedHat'"
args:
name: tar
state: presentservice
自动探测并调用目标机 systemctl 或 service / chkconfig 管理服务状态与自启设置。
支持 --check;仅 SSH;支持 become。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
name | string | 是 | — | Remote service or systemd unit name. |
state | string | started, stopped, restarted, reloaded | Desired state or operation. | |
enabled | boolean | — | Whether to enable startup at boot. Omit to leave it unchanged. |
register 输出字段:status、msg。
示例:
- name: 确保 cron 服务处于运行与开机自启状态
type: service
become: true
args:
name: cron
state: started
enabled: truesystemd
专用于 systemd Linux 主机,支持先执行 systemctl daemon-reload 再管理具体 .service 单元状态和自启。
--check 跳过;仅 SSH。注意:当前 systemd 插件执行 systemctl 命令时不自动拼接 become 包装,操作需要特权的单元时请以 root 连接目标机。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
name | string | 是 | — | Remote service or systemd unit name. |
state | string | started, stopped, restarted, reloaded | Desired state or operation. | |
enabled | boolean | — | Whether to enable startup at boot. Omit to leave it unchanged. | |
daemon_reload | boolean | — | Reload systemd unit definitions. |
register 输出字段:status、msg。
示例:
- name: 重新加载 unit 配置并启动服务
type: systemd
args:
name: demoapp.service
daemon_reload: true
state: started
enabled: truegit
检查远端 .git 目录后执行 git clone 或 git fetch / checkout,并在工作区有本地脏改动且 force: false 时安全拒绝覆盖。
--check 跳过;仅 SSH。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
repo | string | 是 | — | Repository URL or remote-local path. |
dest | string | 是 | — | Remote checkout directory. |
version | string | HEAD | Git branch, tag or revision. | |
force | boolean | — | Reset local changes before updating. |
register 输出字段:status、msg。
示例:
- name: 检出发布分支代码
type: git
args:
repo: "https://git.example.test/team/app.git"
dest: /opt/app-src
version: release-1.0
force: falsedocker
封装 docker 命令行进行幂等容器启停与清理:通过 inspect 比对运行态与镜像名,若镜像不一致则自动销毁重建,已运行且镜像匹配时幂等返回 ok。
--check 跳过;仅 SSH;需要当前连接用户有权调用目标机对应容器引擎。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
name | string | 是 | — | Container name. |
image | string | — | Container image. Provide for state started. | |
state | string | started, stopped, absent | Desired state or operation. | |
ports | array of strings | — | Published port mappings. | |
env | object | — | Container environment values. |
register 输出字段:status、msg。
示例:
- name: 运行 Nginx 反向代理容器
type: docker
args:
name: edge-nginx
image: nginx:alpine
state: started
ports:
- "8080:80"
env:
NGINX_ENV: prodpodman
封装 podman 命令行进行幂等容器启停与清理,行为与 docker 插件一致。
--check 跳过;仅 SSH;需要当前连接用户有权调用目标机对应容器引擎。
参数:
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
name | string | 是 | — | Container name. |
image | string | — | Container image. Provide for state started. | |
state | string | started, stopped, absent | Desired state or operation. | |
ports | array of strings | — | Published port mappings. | |
env | object | — | Container environment values. |
register 输出字段:status、msg。
示例:
- name: 运行 Nginx 反向代理容器
type: podman
args:
name: edge-nginx
image: nginx:alpine
state: started
ports:
- "8080:80"