file.txt
内容如下:
userName = 'ABCD'
password = 'XYZ'
如何使用Ansible playbook在Windows上搜索和替换用户名和密码。
答案 0 :(得分:0)
这可以使用ansible的win_lineinfile模块完成,如下所示。
- name: Update file.txt
win_lineinfile:
dest='c:\file.txt' backrefs=yes state=present
regexp='^\{{ item.search_patttern }}\s*=\s*[\`\~\!\@\#\$\%\^\&\*\(\)\-\+\=\{\[\}\]\\\|\:\;\"\'\<\,\>\.\?\/\w]*'
line="{{ item.replacement }}"
with_items:
- { search_patttern: "username", replacement: "userName = \'NewUser\'" }
- { search_patttern: "password", replacement: "password = \'NewPassword\'" }