首页 > 解决方案 > 我需要更换这个https://localhost:${my.port}${my.context}services/使用 ansible

问题描述

嗨,我需要在 ansible 中替换下面的字符串

' https://localhost :${mgt.transport.https.port}${carbon.context}services/'

使用“本地主机:2222/服务”

我已经使用了一个使用 ansible 的命令。但它不起作用。

 name: set ServerURL of the  AuthManager  [HUB_HOME]/repository/conf/api-manager.xml
 replace: 
    dest: "{{packFolderNameAM}}/repository/conf/api-manager.xml"
    regexp: '<ServerURL>https://localhost:${my.port}${my.context}services/</ServerURL>'- name: set ServerURL of the  AuthManager  [HUB_HOME]/repository/conf/api-manager.xml
    replace: 'localhost/9444/services'
    before: 'Admin username for the Authentication manager'
    backup: yes

请帮我解决一下这个。谢谢!!

标签: ansible

解决方案


因为 api-manager.xml 是一个文件。我们可以保留侧模板:作为不同的文件,并使用标签动态复制文件:在任务中:

这将阻止脚本编写。

或者

保留带有提到的变量的模板,并在剧本 var: 或基于角色的 var /main.yml 文件https://localhost :${my.port}${my.context}services/ 中定义变量然后变量将被填充

例子: 在此处输入图像描述


推荐阅读