{"id":21007959,"url":"https://github.com/lflxp/xp","last_synced_at":"2026-04-13T02:34:02.331Z","repository":{"id":150080996,"uuid":"299598918","full_name":"lflxp/xp","owner":"lflxp","description":"xp is my name,but this project is look like ansible-playbook and pipeline together","archived":false,"fork":false,"pushed_at":"2020-10-09T11:59:48.000Z","size":63,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-20T10:48:25.845Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lflxp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-29T11:42:07.000Z","updated_at":"2020-09-29T11:43:02.000Z","dependencies_parsed_at":"2023-06-05T03:30:07.845Z","dependency_job_id":null,"html_url":"https://github.com/lflxp/xp","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lflxp%2Fxp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lflxp%2Fxp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lflxp%2Fxp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lflxp%2Fxp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lflxp","download_url":"https://codeload.github.com/lflxp/xp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243428436,"owners_count":20289317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T09:10:58.356Z","updated_at":"2025-12-29T03:02:44.213Z","avatar_url":"https://github.com/lflxp.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xp\nxp is my name,but this project is look like ansible-playbook and pipeline together\n\n# 介绍\n\n该项目主要想实现流水线+自动化实现工作和devops都能适应，两者互补。采用技术栈借鉴：\n\n- [x] Ansbile Playbook\n- [x] Gitlab CI\n\n插件接口流程：\n\n* pipeline\n    * User 用户管理\n    * Host 主机清单\n    * Playbook\n        * YAML\n        * module\n    * Plugin\n        * start\n        * stop\n        * status\n        * init\n    * input\n        * host conn check\n        * host env\n        * yaml module 分析\n    * filter\n        * 执行各个module\n            * Role Module\n                * copy\n                * shell\n                * template\n                * ssh\n                * docker\n                * k8s\n                * 网络设备\n                * snmp等\n            * 执行\n                * RPC\n                * RESTFULL\n                * CLI\n        * 管理执行的生命周期\n            * prepare\n            * before\n            * runtime\n            * after\n    * output\n        * 输出结果\n        * 返回状态\n\n# 功能模块\n\n- [x] yaml解析(cobra viper支持)\n  - [ ] 获取环境变量，包括自定义、目标主机基本信息、本地ENV信息等\n  - [x] 识别shell_role中shell、copy、template等三级模块\n  - [x] go template support\n  - [ ] docker support\n  - [ ] k8s support\n  - [ ] ssh + docker support\n  - [x] Hooks钩子函数支撑output plugin输出，目前支持console、email、wechat，todo： phone、sms、elasticsearch、log\n  - [x] tags 指定主机执行\n  - [x] 动态环境变量(cobra支持)\n  - [x] with_items迭代器\n  - [x] 缓存中间产物\n- [x] Debug日志\n- [x] CLI命令行工具(cobra)\n- [ ] 功能文件夹，提供：files、hosts、env等特殊目录模块\n- [ ] roles ansible模块\n- [ ] module man模块说明文档\n- [x] module plugin插件机制\n- [ ] ssh [连接功能](https://github.com/mojocn/felix)\n\n\n# Useage\n\n\u003e go build\n\u003e ./xp test --config devopsxp.yaml\n\n# Test\n\n\u003e make\n\n## 测试执行流程\n\ncli -\u003e main.go -\u003e root.go -\u003e test.go -\u003e pipeline -\u003e init -\u003e start -\u003e check(ssh) -\u003e input(localyaml) -\u003e filter(shell) -\u003e output(console) -\u003e stop\n\n# Module\n\n## Check Plugin\n\n- [x] ssh\n\n## Input Plugin\n\n- [x] localyaml\n\n## Filter Plugin\n\n- [x] shell\n\n## Output Plugin\n\n- [x] console\n\n# 配置信息\n\n本工具采用ssh免密登录进行远程主机命令的执行，需要ssh私钥进行连接，默认获取文件地址为：~/.ssh/id_rsa\n\n## Like Ansible Playbook YAML\n\n### 目标主机配置\n\n配置目标执行主机，支持ip端扫描执行。\n\n```yaml\nhost: # 目标主机\n  - 127.0.0.1\n  - 192.168.0.1-20\n```\n\n### 远程执行用户\n\n```yaml\nremote_user: root\n```\n\n### pipeline管理与stage管理\n\n* roles用于限制stage是否执行，后期可用根据roles来实现流程动态选取\n* stage用于限制config中执行的顺序和stage，没有列入stage的一律不执行\n\n```yaml\nroles: # 执行具体stage\n  - build\n  - test\nstage: # 流程步骤\n  - build\n  - test\n```\n\n### 内置环境变量\n\n用于动态嵌入output输出内容，配合go template实现数据插入。\n\n`todo`：后期考虑加入`本机环境变量`和`远程主机环境变量`，供流程提取数据进行执行操作。\n\n`格式`: 支持任意格式的数据（符合yaml语法），解析采用go template进行，`注意`：变量使用{{.Status}}\n\n```yaml\nvars: # 环境变量\n  Status: true\n  title: \"模板测试\"\n  serviceName: \"xp\"\n  pipelineName: template test\n  pipelineId: no1\n  pipelineUrl: http://www.baidu.com\n  branch: master\n  stage: build\n  tags: test\n  info: test only\n  alerts:\n    - status: firing\n      generatorURL: http://www.google.com\n      startsAt: 2020-08-01\n      endsAt: 2020-09-01\n      annotations:\n        current_value: 85\n      labels:\n        severity: warning\n        node: 127.0.0.1\n        threshold_value: 80\n    - status: ok\n      generatorURL: http://www.google2.com\n      startsAt: 2020-18-01\n      endsAt: 2020-29-01\n      annotations:\n        current_value: 99\n      labels:\n        severity: ok\n        node: 127.0.0.1\n        threshold_value: 88\n```\n\n### Hooks 钩子函数参数配置\n\n消息发送钩子函数参数,支持同时发送多端配置发送，支持类型：\n\n- [x] console\n- [x] email\n- [x] wechat\n- [ ] phone\n- [ ] sms\n- [x] log\n\n```yaml\nhooks: # 消息发送 全局一个 可以一次发送所有结果到多个渠道\n  - type: console # 类型，支持：console|email|wechat|phone|sms\n  - type: email # email邮箱类型\n    alias: xp战队 # 邮箱昵称\n    email_user: \"xp@xp.com\" # 发送邮箱帐号\n    email_pwd: \"xppwdxp\" # 发送邮箱密码\n    email_smtp: \"smtp.exmail.qq.com\" # 邮箱发送smtp服务器\n    email_smtp_port: \"465\" # smtp服务器端口\n    email_to: # 接收邮件人员\n      - xptest@xp.com\n    template: # 告警模板\n      title: \"告警title\" # 标题\n      text: \"{{.Status}} {{.title}}\n      {{range $key,$value := .logs}}\n        {{range $k,$v := $value}}\n        ------ {{$k}} {{$v}}\u003cbr/\u003e\n        {{end}}\n      {{end}}\" # 文本模板\n      path: template.service.j2 # 模板文件路径（与文本模板二选一，同时存在优先选择文本模板）\n      vars: # 内置固定参数\n        Status: true\n        title: \"模板测试\"\n        serviceName: \"xp\"\n  - type: wechat # wechat类型\n    address: # 企业微信机器人地址 支持多机器人批量发送\n      - https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=a-b-c-d-e\n    template: # 告警模板\n      text: '\n# 告警模板\n\n{{if .Status}} \u003cfont color=\\\"info\\\"\u003e[成功] \u003c/font\u003e{{ .title}} {{- else}}\u003cfont color=\\\"warning\\\"\u003e[失败] \u003c/font\u003e {{ .title}}  {{- end}} \n\n\u003e 服务名称：\u003cfont color=\"comment\"\u003e{{.serviceName}}\u003c/font\u003e \n\u003e 流水线名称：\u003cfont color=\"comment\"\u003e{{.pipelineName}}\u003c/font\u003e \n\u003e 流水线ID：\u003cfont color=\"comment\"\u003e{{.pipelineId}}\u003c/font\u003e \n\u003e 流水线地址：\u003cfont color=\"comment\"\u003e{{.pipelineUrl}}\u003c/font\u003e \n\u003e 构建分支：\u003cfont color=\"comment\"\u003e{{.branch}}\u003c/font\u003e \n\u003e 阶段：\u003cfont color=\"comment\"\u003e{{.stage}}\u003c/font\u003e \n\u003e 构建人：\u003cfont color=\"comment\"\u003e{{.user}}\u003c/font\u003e \n\u003e COMMIT: \u003cfont color=\"comment\"\u003e{{.info}}\u003c/font\u003e \n\u003e COMMITID：\u003cfont color=\"comment\"\u003e{{.tags}}\u003c/font\u003e\n\n# {{.title}}\n\n{{range $key,$value := .logs}}\n{{range $k,$v := $value}}\n\u003e {{$k}} {{$v}}\n{{end}}\n{{end}}' # 文本模板\n      path: template.service.j2 # 模板文件路径（与文本模板二选一，同时存在优先选择文本模板）\n      vars: # 内置固定参数（与全局vars共享数据，这里设置相同参数会覆盖全局key）\n        title: \"模板测试\"\n        serviceName: \"xp\"\n  - type: phone\n  - type: sms\n```\n\n### 详细stage config配置\n\n这里是主要的逻辑编写单元，实现各种pipeline的编写和stage的区分，目前支持的模块有：\n\n- shell 模块，执行shell命令\n- template 模块，执行基于go template的模板渲染和远程上传\n- copy 模块，执行本地文件上传到目标主机指定地址\n\n```yaml\nconfig: # 详细配置信息\n  - stage: build\n    name: template 模板测试\n    template: \n      src: template.service.j2 \n      dest: /tmp/docker.service\n  - stage: test\n    name: 上传文件\n    copy: \n      src: \"{{ .item }}\"\n      dest: /tmp/{{ .item }}\n    with_items:\n      - LICENSE\n      - 2\n      - 3\n  - stage: what\n    name: 非stage测试\n    shell: whoami\n  - stage: build\n    name: 获取go version\n    shell: lsb_release -a\n  - stage: test\n    name: 获取主机名\n    shell: \"{{.item}}\"\n    with_items:\n    - hostname\n    - ip a|grep eth0\n    - pwd\n    - uname -a\n    - docker ps \u0026\u0026 \n      docker images\n  - stage: test\n    name: 查看docker信息\n    shell: systemctl status sshd\n```\n\n## Template 模板示例，采用go template，value来自上面`YAML` template模块的vars选项\n\n```go\n{{if .Status}} \u003cfont color=\"info\"\u003e[成功] \u003c/font\u003e{{ .title}} {{- else}}\u003cfont color=\"warning\"\u003e[失败] \u003c/font\u003e {{ .title}}  {{- end}} \n\u003e 服务名称：\u003cfont color=\"comment\"\u003e{{.serviceName}}\u003c/font\u003e \n流水线名称：\u003cfont color=\"comment\"\u003e{{.pipelineName}}\u003c/font\u003e \n流水线ID：\u003cfont color=\"comment\"\u003e{{.pipelineId}}\u003c/font\u003e \n流水线地址：\u003cfont color=\"comment\"\u003e{{.pipelineUrl}}\u003c/font\u003e \n构建分支：\u003cfont color=\"comment\"\u003e{{.branch}}\u003c/font\u003e \n阶段：\u003cfont color=\"comment\"\u003e{{.stage}}\u003c/font\u003e \n构建人：\u003cfont color=\"comment\"\u003e{{.user}}\u003c/font\u003e \nCOMMITID：\u003cfont color=\"comment\"\u003e{{.tags}}\u003c/font\u003e \nCOMMITINFO: \u003cfont color=\"comment\"\u003e{{.info}}\u003c/font\u003e \n\n{{range $e := .alerts}}\n## {{if eq $e.status \"firing\"}} [\u003cfont color=\"warning\"\u003e{{$e.labels.severity}}\u003c/font\u003e] {{ $e.labels.node}} [监控详情]({{$e.generatorURL}})\n\n\u003e\u003e 告警阈值: \u003cfont color=\"warning\"\u003e{{$e.labels.threshold_value}}\u003c/font\u003e \n当前数值: \u003cfont color=\"warning\"\u003e{{$e.annotations.current_value}}\u003c/font\u003e \n开始时间: \u003cfont color=\"comment\"\u003e{{$e.startsAt}}\u003c/font\u003e \n结束时间: \u003cfont color=\"comment\"\u003e{{$e.endsAt}}\u003c/font\u003e \n\n{{- else}}# [\u003cfont color=\"info\"\u003e{{$e.labels.severity}}\u003c/font\u003e] {{ $e.labels.node}} [监控详情]({{$e.generatorURL}})\n\n\u003e\u003e 告警阈值: \u003cfont color=\"info\"\u003e{{$e.labels.threshold_value}}\u003c/font\u003e \n当前数值: \u003cfont color=\"info\"\u003e{{$e.annotations.current_value}}\u003c/font\u003e \n开始时间: \u003cfont color=\"comment\"\u003e{{$e.startsAt}}\u003c/font\u003e \n结束时间: \u003cfont color=\"comment\"\u003e{{$e.endsAt}}\u003c/font\u003e \n\n{{- end}}\n\n{{end}}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flflxp%2Fxp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flflxp%2Fxp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flflxp%2Fxp/lists"}