여러 호스트 이름을 통해 실행할 때 ansible을 통해 파일에 중복 값을 인쇄하기 위해 lineinfile 대신 사용할 것

sakki

내 플레이 북은 Tanium 클라이언트 구성 설정 값이 동일한 여러 호스트에서 실행 중입니다. lineinfile 모듈을 사용하여 파일의 각 작업 값을 인쇄했습니다. 두 번째 호스트에서 실행하는 동안 첫 번째 호스트에서 이미 현재 값을 건너 뛰는 것입니다. 모든 인벤토리 호스트 이름에 대한 파일에서 값이 중복 되더라도 인쇄하고 싶습니다. 다음은 코드입니다.

- name: main execution
  hosts: dc
  become: true
  gather_facts: no
  serial: 1
  tasks:
       - name: fetch conf setting
         shell: /opt/Tanium/TaniumClient/TaniumClient config list | grep -i -e 'ListenPort' -e 
         'ServerName' -e 'ServerNameList' -e 'ServerPort'
         register: output2

       - lineinfile:
         line: "{{item}}"
         path: "{{playbook_dir}}/output.txt"
         with_items:
         - "{{ output2.stdout_lines }}"
         connection: local

플레이 북 실행 후 첫 번째 호스트 의 상태는 다음과 같습니다 .

         TASK [fetch conf setting] 
***************************************************************************************
changed: [firsthost.com]

TASK [lineinfile] 
**********************************************************************************************
changed: [firsthost.com] => (item= The conf value for firsthost.com)
changed: [firsthost.com] => (item=  - LastGoodServerName: anenp.host.com)
changed: [firsthost.com] => (item=  - ListenPort: 17472)
changed: [firsthost.com] => (item=  - ServerName: anenp.host.com)
changed: [firsthost.com] => (item=  - ServerNameList: anenp.host.com,anenpc.host.com)
changed: [firsthost.com] => (item=  - ServerPort: 443)

위에서 언급했듯이 첫 번째 호스트의 모든 값이 파일에 인쇄됩니다.

플레이 북이 두 번째 호스트에서 실행 되면 공통 값을 건너 뜁니다. 상태는 다음과 같습니다.

TASK [fetch conf setting] 
 *******************************************************************************************
changed: [secondhost.com]

TASK [lineinfile] 
****************************************************************************************
changed: [secondhost.com] => (item= The conf value for secondhost.com)
changed: [secondhost.com] => (item=  - LastGoodServerName: anen100.host.com)
**ok: [secondhost.com] => (item=  - ListenPort: 17472)**
changed: [secondhost.com] => (item=  - ServerName: anen100.host.com)
**ok: [secondhost.com] => (item=  - ServerNameList: 
anenp.host.com,anenpc.host.com)
ok: [secondhost.com] => (item=  - ServerPort: 443)**

파일에서 중복 값에 관계없이 모든 값을 인쇄하는 방법은 무엇입니까?

부여 blockinfile시도 :

- blockinfile:
    block: "{{ output2.stdout }}"
    path: "{{playbook_dir}}/output.txt"
    marker: ""
  connection: local

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관