본문 바로가기
인프라/앤서블(Ansible)

[Ansible] 앤서블 와일드카드 find 아스테리크

by IT맥구리나스 2022. 7. 30.
- hosts: all
  become: yes
  vars:
    ansible_become_password: "{{ sudopasswd }}"
  tasks:
    - name: deploy check script
      copy:
        src: /data/ansible/file/scripttest.sh
        dest: /tmp/Unix_v1.3.3_contain_web_was.sh
        mode: 0755
        #user: "infra"

    - name: exec check script
      shell:
        cmd: /tmp/scripttest.sh
      register: result

    - name: result
      debug:
        msg: "{{ result.stdout_lines }}"
    - name: find result file
      find:
        paths: "/home/infra"
        recurse: no
        patterns: "*.tar.gz"
      register: result_file


    - name: fetch result file
      fetch:
        src: "{{ item.path }}"
        dest: "/data/ansible/file/check_result/"
        flat: yes
      with_items: "{{ result_file.files }}"

앤서블은 와일드카드문을 사용할 수 없다.

그래서 find 모듈을 이용하여 파일명을 찾아 이것을 변수로 활용한다

 

copy 나 fetch 모듈에서 사용한다.

 

find의 찾은 결과가 여러개 일수 있으니, 1개든 2개든 올바르게 활용하려고 반복문(with_items)을 사용한다.

아래 결과를 보면 msg에 find로 찾은 파일명의 결과를 볼수 있다.

ansible find

ansible 아스테리크

ansible wildcard

반응형

댓글