2016-10-19 8 views
1

디렉토리의 여러 .conf 파일에 줄을 추가하고 싶습니다. /etc/abc/xabc/. 디렉토리의 여러 파일에 여러 줄을 추가하는 방법

내가 추가 할 두 개의 선이

은 다음과 같습니다 :

Composite=1 
Extension=1 

내가 [protocol]을 포함하는 행 다음에 나타나는이 줄을 싶습니다.

어떻게하면됩니까?

이 작업을 진행하는 방법을 모르겠습니다. 아래 내 시도를 참조 - 나는 그것이 잘못 알고 비록 :

- name: add line 

- lineinfile: 
    dest: "{{ item }}" 
    regexp: "{{ item.regexp }}" 
    line: "{{ item.line }}" 
    insertafter: [Protocol] 
    with_items: xxxxxx 

을 나는 또한 (/etc/abc/xabc/) 디렉토리의 출력을 등록해야 같은데요? 당신은 INI 파일을 편집 할 같은

답변

2

첫째, 그것은 보이는, 그래서 ini_file 모듈은 훨씬 더 적절하다 : 중첩 루프를 사용하려는처럼

- ini_file: 
    dest: /path/to/destination/file.ini 
    section: Protocol 
    option: "{{ item.option }}" 
    value: "{{ item.value }}" 
    with_items: 
    - { option: Composite, value: 1 } 
    - { option: Extension, value: 1 } 

둘째, 그것은 보인다. 명확성을 위해, 나는 목적지 디렉토리의 fileglob에 대해 외부 루프에있는 파일을 포함시키고 포함 된 파일에서 구성을 수행 할 것이다. 예를 들어, inner_loop.yml :

- ini_file: 
    dest: "{{ destination_file }}" 
    section: Protocol 
    option: "{{ item.option }}" 
    value: "{{ item.value }}" 
    with_items: 
    - { option: Composite, value: 1 } 
    - { option: Extension, value: 1 } 

외측 :

- include: inner_loop.yml 
    with_fileglob: 
    - /etc/abc/xabc/* 
    loop_control: 
    loop_var: destination_file 

This answer는 글로브 위에 루프 항목 위에 루프를 결합하기위한 다른 가능한 솔루션을 제안한다.