2017-12-28 41 views
1

다음 내용이있는 clado.txt라는 샘플 파일이 있습니다.라인 파일 모듈과 관련된 문제

[server] 

[backend] 

[frontend] 

은 내가 [서버] 섹션에서 선 "apache1을"인세하려합니다.

[server] 
apache1 

[backend] 

[frontend] 

내 작전

--- 
- hosts: aws 
    become: yes 
    remote_user: ec2-user 
    tasks: 
    - name: editing /home/ec2-user/clado.txt. 
    lineinfile: 
     dest: /home/ec2-user/clado.txt 
     insertafter: "[server]" 
     line: "apche1" 

하지만 내가 원하는 출력을 받고 있지 않다.

[server] 

[backend] 

[frontend] 
apche1 

어떻게 [서버]

+0

작성중인 INI 파일과 유사합니다. 그것이 작동하는지 잘 모르겠지만 체크 아웃 http://docs.ansible.com/ansible/latest/ini_file_module.html,이게 도움이 될거야. –

답변

0

역 슬래시와 괄호를 탈출 할 필요가 있으므로 insertafter의 인수는, 정규 표현식이다 아래의 단어 "apache1"를 배치 할 수 있습니다.

insertafter: "\\[server\\]" 

사례의 대부분에서, 당신은 Ansible template module를 사용해야하는 대신 대상 시스템의 현재 상태에 의존, 원하는 내용을 지정합니다.

+0

큰 따옴표가있는 두 개의 백 슬래시 또는 한 개의 따옴표가있는 백 슬래시가 필요합니다. – techraf