【问题标题】:Is it possible to set flags when using make with Ansible?将 make 与 Ansible 一起使用时是否可以设置标志?
【发布时间】:2021-09-02 11:16:10
【问题描述】:

我想知道是否可以使用ansiblecommunity.general.make 模块在ansible 中传递以下命令:

make -C safenet install PREFIX=~/.local

我必须使用params,如here 所述吗?例如

- name: installing safenet
  community.general.make:
    chdir: ~/myfiles/safenet
    target: install
    params:
      - "-C"
      - PREFIX=~/.local

编辑:这是我得到的输出。

TASK [Installing safenet] *******************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "argument 'params' is of type <class 'list'> and we were unable to convert to dict: <class 'list'> cannot be converted to a dict"}

【问题讨论】:

  • 尝试时会发生什么?
  • 请看我更新的答案。

标签: makefile ansible


【解决方案1】:

如果其他人对此有疑问,这是一个相当简单的解决方法:您只需要使用 params 传递参数。由于此模块喜欢使用~ 作为主文件夹,因此您需要使用变量或插件使其使用当前用户 ($USER) 的 home 文件夹。例如

- name: "Your task"
  community.general.make:
    chdir: /home/{{ lookup('env', 'USER') }}/path/to/makefile
    target: install
    params: PREFIX=/home/{{ lookup('env', 'USER') }}/path/you/want/to/use

{{ lookup('env', 'USER') }} 使 Ansible 查找当前用户名。

希望这对将来的其他人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-17
    • 1970-01-01
    • 2017-05-13
    • 2021-11-12
    • 2016-04-01
    • 2011-01-20
    • 2018-08-11
    • 2021-08-05
    相关资源
    最近更新 更多