![Ansible 是否提供一种在控制节点上构建/编译,然后部署到管理节点的方法?](https://linux22.com/image/764137/Ansible%20%E6%98%AF%E5%90%A6%E6%8F%90%E4%BE%9B%E4%B8%80%E7%A7%8D%E5%9C%A8%E6%8E%A7%E5%88%B6%E8%8A%82%E7%82%B9%E4%B8%8A%E6%9E%84%E5%BB%BA%2F%E7%BC%96%E8%AF%91%EF%BC%8C%E7%84%B6%E5%90%8E%E9%83%A8%E7%BD%B2%E5%88%B0%E7%AE%A1%E7%90%86%E8%8A%82%E7%82%B9%E7%9A%84%E6%96%B9%E6%B3%95%EF%BC%9F.png)
答案1
对于 Ansible,要在不同的主机集上运行某事物,请尝试启动一个新的剧本。
- name: Build thing
# localhost is the node running Ansible
# By default, this already is connection local
# exec instead of ssh
hosts: localhost
tasks:
# Assuming make based build scripts
# make module reports not changed if nothing to do
- make:
chdir: /home/builduser/source/thing/
- name: Install thing
hosts: various
tasks:
- copy:
# copy is an action plugin that handles the copy from localhost to remote for yoy
src: /home/builduser/source/thing/output/thing.rpm
dest: /tmp/thing.rpm
# TODO Use custom repo for content management rather than copying one-off packages
- package:
name: /tmp/thing.rpm
尽管你可以在 CI/CD 管道或其他任何地方运行 Ansible,而且它可以运行任何你喜欢的东西,但 Ansible 作为构建系统并不出色。它不是面向工件的。
答案2
您可以创建一个简单的任务来调用make
如下命令localhost
:
- name: make an executable
command: make
tags: compile
delegate_to: localhost
connection: local
run_once: True
become: no
这将运行 make 命令并执行 Makefile 中的所有内容。然后在下一个任务中,您可以创建一个复制任务以将结果复制到托管节点。