Is there with_fileglob that works remotely in ansible?

前端 未结 4 997
说谎
说谎 2020-12-10 00:49

Is there with_fileglob that works remotely in ansible?

Mainly I do want to use something similar with the with_fileglob but that will glob

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 01:35

    Here's a way to do it so that you can loop through all found. In my example, i had to look for all instances of pip to wipe out awscli in preparation to install awscli v2.0. I've done similar with lineinfile to strip out vars in /etc/skel dotfiles

    - name: search for pip
      find:
        paths: [ /usr/local/bin, /usr/bin ]
        file_type: any
        pattern: pip*
      register: foundpip
    
    - name: Parse out pip paths (say that 3 times fast)
      set_fact:
        pips: "{{ foundpip | json_query('files[*].path') }}"
    
    - name: List all the found versions of pip
      debug:
        msg: "{{ pips }}"
    
    #upgrading pip often leaves broken symlinks or older wrappers behind which doesn't affect pip but breaks playbooks so ignore!
    - name: remove awscli with found versions of pip
      pip:
        name: awscli
        state: absent
        executable: "{{ item }}"
      loop: "{{ pips }}"
      ignore_errors: yes
    

提交回复
热议问题