将文件复制到ansible主机并替换自定义变量

fer*_*rdy 4 copy ansible ansible-playbook

我正在开发一个ansible-playbook,它应该有助于为持续交付管道生成构建代理.在其他问题中,我需要在这样的代理上安装oracle客户端.我想做点什么

- name: "Provide response file"
  copy: src=/custom.rsp dest=/opt/oracle 
Run Code Online (Sandbox Code Playgroud)

在custom.rsp文件中,我有一些变量要替换.通常,可以使用单独的shell命令来执行此操作:

- name: "Substitute Vars"
  shell: "sed 's|<PARAMETER>|<VALUE>|g' -i /opt/oracle/custom.rsp"
Run Code Online (Sandbox Code Playgroud)

不过我不喜欢它.应该有一种更方便的方法来做到这一点.有人给我一个暗示吗?

Bru*_*e P 7

您希望使用模板而不是复制静态文件.

此外,使用复制或模板模块时,dest参数是完整路径AND文件名,而不仅仅是路径.因此,如果您想custom.rsp在目录/ opt/oracle中得到一份副本,那么您需要这样做:

- name: "Provide response file"
  template: src=/custom.rsp dest=/opt/oracle/custom.rsp
Run Code Online (Sandbox Code Playgroud)