ansible:如何传递多个命令 [英] ansible : how to pass multiple commands

查看:22
本文介绍了ansible:如何传递多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过了:

- command: ./configure chdir=/src/package/
- command: /usr/bin/make chdir=/src/package/
- command: /usr/bin/make install chdir=/src/package/

它有效,但我想还有更多的东西......整洁.

which works but I guess there is something more.. neat.

所以我尝试了这个:

来自:https://stackoverflow.com/questions/24043561/multiple-commands-in-the-same-line-for-bruker-topspin 这让我回复没有这样的文件或目录"

from: https://stackoverflow.com/questions/24043561/multiple-commands-in-the-same-line-for-bruker-topspin which give me back "no such file or directory"

- command: ./configure;/usr/bin/make;/usr/bin/make install chdir=/src/package/

我也试过这个:https://u.osu.edu/hasnan.1/2013/12/16/ansible-run-multiple-commands-using-command-module-and-with-items/

但我找不到合适的语法:

but I couldn't find the right syntax to put:

- command: "{{ item }}" chdir=/src/package/
  with_items:
      ./configure
      /usr/bin/make
      /usr/bin/make install

这不起作用,说存在报价问题.

That does not work, saying there is a quote issue.

有人吗?

推荐答案

如果 YAML 中的值以花括号 ({) 开头,则 YAML 解析器假定它是 一本字典.因此,对于这种值中有(Jinja2)变量的情况,需要采用以下两种策略之一来避免混淆 YAML 解析器:

If a value in YAML begins with a curly brace ({), the YAML parser assumes that it is a dictionary. So, for cases like this where there is a (Jinja2) variable in the value, one of the following two strategies needs to be adopted to avoiding confusing the YAML parser:

引用整个命令:

- command: "{{ item }} chdir=/src/package/"
  with_items:
  - ./configure
  - /usr/bin/make
  - /usr/bin/make install    

或者改变参数的顺序:

- command: chdir=/src/package/ {{ item }}
  with_items:
  - ./configure
  - /usr/bin/make
  - /usr/bin/make install

感谢@RamondelaFuente 的替代建议.

这篇关于ansible:如何传递多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆