答案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 中的所有内容。然后在下一个任务中,您可以创建一个复制任务以将结果复制到托管节点。