跳到内容
FleetKiteFleetKite

内置插件

27 个内置插件与 3 个编排指令的完整参考。

FleetKite 内置 27 个插件 与 3 个编排指令(与 fleetkite plugins list 输出一致)。

本页的参数表由引擎自身导出,因此不会与实际注册的参数产生偏差;任何时候都可以用 fleetkite plugins show <名称> 拿到同样的信息。

能力与行为速查表

名称分类--check 预演--diffconnection: localbecome 提权典型 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_fileSFTP 传输支持支持仅 SSH支持diff(文本单文件 --diff 时)
template模板渲染支持支持支持支持diff(开启 --diff 时)
unarchive归档解压支持—支持支持src, dest
get_url远端下载支持—支持支持url, dest
httpHTTP 请求仅放行只读方法—支持—status_code(可选 json, content)
wait_for端口 / 文件等待支持(只读)—支持(仅文件)—status, msg
userLinux 用户跳过—仅 SSH支持stdout
cron计划任务支持—仅 SSH支持status, msg
aptDebian 软件包支持—仅 SSH支持status, msg
yum / dnfRedHat 软件包支持—仅 SSH支持status, msg
service通用服务支持—仅 SSH支持status, msg
systemdSystemd 单元跳过—仅 SSH不支持(需直连特权用户)status, msg
gitGit 仓库跳过—仅 SSH—status, msg
docker / podman容器管理跳过—仅 SSH—status, msg

插件详情

include_tasks

运行到达该步骤时从本地读取一个 YAML 任务列表文件并按顺序展开执行。validate / inspect 对主剧本离线校验时仅记录声明,实际内容在运行期加载;支持继承父任务的 when(逐一评估)、tags、become*、connection、delegate_to。

在角色内优先按 当前任务目录 -> roles/<name>/tasks/ -> roles/<name>/ 查找目标文件。

参数:

参数类型必填默认值说明
filestring是—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>/ 查找。

参数:

参数类型必填默认值说明
filestring是—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 不存在时跳过,显式指定不存在时报错。

参数:

参数类型必填默认值说明
namestring是—Role name.
tasks_fromstringmainTask file under roles/<name>/tasks/ without requiring a .yml/.yaml suffix.
vars_fromstring—Variable file under roles/<name>/vars/.
handlers_fromstring—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: main

shell

在远程 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。

参数:

参数类型必填默认值说明
commandstring是—Remote command.
expect_pairsarray of objects—Optional interactive prompt/answer pairs using prompt and answer keys.
end_promptstring[#$]\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,但查询动作自身不会报错中断。

参数:

参数类型必填默认值说明
jidstring是—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: 2

expect

为带交互提示(如初始化脚本、密码确认、passwd 等)的命令提供正则匹配与自动回复(支持从 Vault 解密安全应答文本)。

--check 跳过;仅 SSH;支持 become;强烈建议涉密任务开启 no_log: true。

参数:

参数类型必填默认值说明
commandstring是—Remote command.
responsesobject是—Map prompt patterns to responses.
timeoutinteger30Timeout in seconds.
end_promptstring—Completion prompt pattern.
chdirstring—Remote working directory.
output_varstring—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_facts

set_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: true

debug

在执行输出中打印指定消息、变量路径内容(受 ***MASKED*** 保护),或在两者皆省略时打印当前全部变量快照。

支持 --check 与 connection: local;默认返回 status: ok,不计作变更。

参数:

参数类型必填默认值说明
msgstring—Message.
varstring—Variable name or dotted path.
verbosityinteger—Skip the message when greater than zero.

register 输出字段:指定 var 时返回 var、value;指定 msg 时返回 msg;均省略时返回 variables。

示例:

- name: 打印探测到的网卡主 IP
  type: debug
  args:
    var: fleetkite_default_ipv4.address

assert

验证一条或多条 CEL 表达式是否全为真;任意一条为假即判定任务失败并终止流程(除非 ignore_errors: true 或被 rescue 捕获)。

支持 --check 与 connection: local。

参数:

参数类型必填默认值说明
thatstring or array of strings是—One CEL expression or a list of expressions.
success_msgstring—Message on success.
fail_msgstring—Message on failure.
quietboolean—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。

参数:

参数类型必填默认值说明
msgstring—Failure message.
whenstring—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 等高危根目录(但仍可递归删除常规非空子目录,请核对路径安全)。

参数:

参数类型必填默认值说明
pathstring是—Remote filesystem path.
statestringfile, directory, touch, absentDesired state or operation.
modestring—Octal mode as a quoted string, for example '0644'.
ownerstring—Remote owner.
groupstring—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
    - logs

stat

只读探测文件是否存在、文件类型、大小、权限、属主及 SHA-256 / MD5 哈希。

只读,支持 --check 与 connection: local。

参数:

参数类型必填默认值说明
pathstring是—Remote filesystem path.
get_checksumboolean—Calculate SHA-256.
get_md5boolean—Calculate MD5.
followboolean—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_stat

lineinfile

幂等保障配置文件中某一行存在(支持正则匹配替换、在指定位置前 / 后插入、备份原文件)或删除匹配行。

支持 --check、--diff、connection: local 与 become(当采用 become 或 local 时采用完整文件内容快照与原子替换保证安全)。

参数:

参数类型必填默认值说明
pathstring是—Remote filesystem path.
linestring—Required when state is present.
regexpstring—Go regular expression for the target line.
statestringpresent, absentDesired state or operation.
createboolean—Allow creating a missing file.
backupboolean—Save the previous content before replacing the file.
insertafterstring—Insertion pattern or EOF.
insertbeforestring—Insertion pattern or BOF.
modestring—Octal mode as a quoted string, for example '0644'.
ownerstring—Remote owner.
groupstring—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_pathstring是—Controller-side path.
remote_pathstring是—Absolute path on the target.
directionstringupload, downloadDesired state or operation.
recursiveboolean—Upload a workspace directory.
compressionstringnone, gzipUse gzip only for recursive uploads where saving bandwidth matters.
excludearray of strings—Exclude matching names or workspace-relative paths during recursive upload.
modestring—Octal mode as a quoted string, for example '0644'.
ownerstring—Remote owner.
groupstring—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 等函数。

参数:

参数类型必填默认值说明
srcstring是—Local template source.
deststring是—Remote destination.
modestring—Octal mode as a quoted string, for example '0644'.
ownerstring—Remote owner.
groupstring—Remote group.
enginestringdefault, gotmplDesired state or operation.
delimitersarray 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:
    - 重启 DemoApp

unarchive

将控制端本地压缩包先上传(或直接读取目标机已存在的压缩包)并解压至远端目录;支持 connection: local 在控制端本机解压(支持 tar / tar.gz / tgz / tar.bz2 / tbz2 / zip,并做严密成员路径穿越 / 数量 / 总大小检查)。

支持 --check、connection: local(本地不支持 extra_opts)、become。

参数:

参数类型必填默认值说明
srcstring是—Archive path.
deststring是—Remote destination directory.
remote_srcboolean—Read src on the target instead of uploading it.
createsstring—Skip when this remote path already exists.
extra_optsstring—Additional archive tool options.
modestring—Octal mode as a quoted string, for example '0644'.
ownerstring—Remote owner.
groupstring—Remote group.

register 输出字段:实际执行解压变更后包含 src、dest。

示例:

- name: 解压发布包(存在 VERSION 文件时幂等跳过)
  type: unarchive
  args:
    src: fixtures/demoapp-pkg.tar.gz
    dest: /opt/demoapp
    creates: /opt/demoapp/VERSION

get_url

使用目标主机上的 curl 或 wget(connection: local 下使用 Go HTTP 客户端)下载制品文件并校验摘要。

支持 --check、connection: local、become。目标文件已存在且校验一致时直接返回 ok。

参数:

参数类型必填默认值说明
urlstring是—HTTP or HTTPS URL.
deststring是—Remote destination file.
checksumstring—Expected checksum, for example sha256:<hex>.
forceboolean—Download even if the destination already exists.
timeoutinteger30Download timeout in seconds.
headersobject or string—Map of headers or a single header line.
modestring—Octal mode as a quoted string, for example '0644'.
ownerstring—Remote owner.
groupstring—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)。

参数:

参数类型必填默认值说明
urlstring是—HTTP(S) endpoint. Do not put credentials in the URL.
methodstringGET, HEAD, OPTIONS, POST, PUT, PATCH, DELETEDesired state or operation.
locationstringcontrol, targetDesired state or operation.
headersobject—Map from header name to string value.
status_codeinteger or array of integers200Expected HTTP status code or list of codes.
timeoutinteger10Request timeout in seconds.
body_formatstringtext, jsonDesired state or operation.
return_contentboolean—Expose raw response content in the registered result.
json_bodyany—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_health

wait_for

轮询检测 TCP 端口监听状态、文件出现 / 消失或文件内正则出现 / 消失(常用于服务重启后就绪等待)。

只读等待,支持 --check;connection: local 仅支持 path 文件检测(TCP 端口检测需要 SSH 连接用于建隧道)。

参数:

参数类型必填默认值说明
hoststring—Endpoint for TCP checks. Defaults to 127.0.0.1 from the target.
portinteger—TCP port to check.
pathstring—Remote file to check.
statestringstarted, stopped, present, absentDesired state or operation.
timeoutinteger300Maximum wait in seconds.
delayinteger—Initial delay in seconds.
search_regexstring—Required file content pattern.
exclude_regexstring—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: 30

user

基于目标机 useradd / usermod / userdel / chpasswd 幂等创建、更新或删除本地用户账号。

--check 跳过;仅 SSH;支持 become;管理密码时建议搭配 Vault 并开启 no_log: true。

参数:

参数类型必填默认值说明
namestring是—Target account name.
statestringpresent, absentDesired state or operation.
uidinteger or string—Numeric user ID.
groupstring—Primary group.
groupsarray of strings—Supplementary groups. Omit to preserve existing membership.
shellstring—Login shell.
homestring—Home directory.
commentstring—Account description.
create_homebooleanTrueCreate the home directory.
removeboolean—Also remove the home directory when the account is removed.
passwordstring—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: true

cron

在目标用户 crontab 中创建、更新、注释禁用(disabled: true)或移除由 #FleetKite: <name> 标记管理的计划任务,绝不误删手工维护的其他行。

支持 --check;仅 SSH;支持 become。

参数:

参数类型必填默认值说明
namestring是—FleetKite crontab entry name.
jobstring—Command required when state is present.
minutestring*Cron minute.
hourstring*Cron hour.
daystring*Day of month.
monthstring*Cron month.
weekdaystring*Day of week.
userstring—Crontab owner. Omit for the current user.
statestringpresent, absentDesired state or operation.
disabledboolean—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: present

apt

基于 dpkg -s 幂等校验并用 apt-get 安装 / 卸载软件包(也支持传入受控机上的本地 .deb 文件路径安装)。

支持 --check;仅 SSH;支持 become。

参数:

参数类型必填默认值说明
namestring是—Package name. apt also accepts a local .deb path on the target.
statestringpresent, absentDesired state or operation.
update_cacheboolean—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: present

yum

基于 rpm -q 幂等检查并调用 yum 前端安装 / 移除软件。

支持 --check;仅 SSH;支持 become。

参数:

参数类型必填默认值说明
namestring是—Package name.
statestringpresent, absentDesired state or operation.
update_cacheboolean—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: present

dnf

基于 rpm -q 幂等检查并调用 dnf 前端安装 / 移除软件(内部同时兼容回退到 yum)。

支持 --check;仅 SSH;支持 become。

参数:

参数类型必填默认值说明
namestring是—Package name. apt also accepts a local .deb path on the target.
statestringpresent, absentDesired state or operation.
update_cacheboolean—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: present

service

自动探测并调用目标机 systemctl 或 service / chkconfig 管理服务状态与自启设置。

支持 --check;仅 SSH;支持 become。

参数:

参数类型必填默认值说明
namestring是—Remote service or systemd unit name.
statestringstarted, stopped, restarted, reloadedDesired state or operation.
enabledboolean—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: true

systemd

专用于 systemd Linux 主机,支持先执行 systemctl daemon-reload 再管理具体 .service 单元状态和自启。

--check 跳过;仅 SSH。注意:当前 systemd 插件执行 systemctl 命令时不自动拼接 become 包装,操作需要特权的单元时请以 root 连接目标机。

参数:

参数类型必填默认值说明
namestring是—Remote service or systemd unit name.
statestringstarted, stopped, restarted, reloadedDesired state or operation.
enabledboolean—Whether to enable startup at boot. Omit to leave it unchanged.
daemon_reloadboolean—Reload systemd unit definitions.

register 输出字段:status、msg。

示例:

- name: 重新加载 unit 配置并启动服务
  type: systemd
  args:
    name: demoapp.service
    daemon_reload: true
    state: started
    enabled: true

git

检查远端 .git 目录后执行 git clone 或 git fetch / checkout,并在工作区有本地脏改动且 force: false 时安全拒绝覆盖。

--check 跳过;仅 SSH。

参数:

参数类型必填默认值说明
repostring是—Repository URL or remote-local path.
deststring是—Remote checkout directory.
versionstringHEADGit branch, tag or revision.
forceboolean—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: false

docker

封装 docker 命令行进行幂等容器启停与清理:通过 inspect 比对运行态与镜像名,若镜像不一致则自动销毁重建,已运行且镜像匹配时幂等返回 ok。

--check 跳过;仅 SSH;需要当前连接用户有权调用目标机对应容器引擎。

参数:

参数类型必填默认值说明
namestring是—Container name.
imagestring—Container image. Provide for state started.
statestringstarted, stopped, absentDesired state or operation.
portsarray of strings—Published port mappings.
envobject—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: prod

podman

封装 podman 命令行进行幂等容器启停与清理,行为与 docker 插件一致。

--check 跳过;仅 SSH;需要当前连接用户有权调用目标机对应容器引擎。

参数:

参数类型必填默认值说明
namestring是—Container name.
imagestring—Container image. Provide for state started.
statestringstarted, stopped, absentDesired state or operation.
portsarray of strings—Published port mappings.
envobject—Container environment values.

register 输出字段:status、msg。

示例:

- name: 运行 Nginx 反向代理容器
  type: podman
  args:
    name: edge-nginx
    image: nginx:alpine
    state: started
    ports:
      - "8080:80"

本页目录