파일에서 단어를 찾고 ansible을 사용하여 대체하려고합니다.
문제는 단어에 종료 정규식 특수 문자 $-$ wordToFind가 포함되어 있다는 것입니다.
이미 [$] wordToFind 또는 \ $ wordToFind를 사용하여 이스케이프를 시도했습니다. 이것은 내가 사용하는 코드입니다.
- name: Check if the /pathToFile/file.ext file contains the entry value $wordToFind
shell: "cat /pathToFile/file.ext | grep \"schwordToFindeme\""
become: yes
become_method: sudo
failed_when: false
register: cat_result
when: condition == "A"
- name: change to newWord if $wordToFind was found
replace:
dest: //pathToFile/file.ext
regexp: "$wordToFind"
replace: "newWord"
backup: yes
when: cat_result.rc > 0 and condition == "A"
작은 따옴표로 변경하십시오. 아래 하나가 나를 위해 일했습니다.
- name: change to newWord if $wordToFind was found
replace:
dest: //pathToFile/file.ext
regexp: '\$wordToFind'
replace: 'newWord'
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다