大网数据广告活动
服务器运维问答

Does Ansible offer a way to build/compile on the control node, and then deploy to managed nodes?

· 52CE 我爱测

Is there any way to have Ansible run a build script locally on the control node, and then deploy the resulting artifact to various managed nodes? Please let me know if there's something I've missed, but I looked at the docs for t…

问题原文

原帖链接 · bjmc · CC BY-SA 4.0

Is there any way to have Ansible run a build script locally on the control node, and then deploy the resulting artifact to various managed nodes?

Please let me know if there's something I've missed, but I looked at the docs for the shell, command and script modules, and they each only seem to allow execution on the managed node. I'm really surprised I can't find a way to run a command on the control node.

Maybe this isn't in Ansible's wheelhouse? Is the idea that you're supposed to use some other tool like Make to do the build, and then Ansible only handles copying it to servers?

已采纳解答

原帖链接 · John Mahowald · CC BY-SA 4.0

For Ansible, to run a thing on a different set of hosts, try starting a new play.

- 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

Although you can run Ansible in CI/CD pipelines or whatever, and it can run whatever you like, Ansible is not amazing at being a build system. It is not artifact oriented.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-02-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。