Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

regex - Extract filename from file result in ansible

I'm trying to use the result of Ansible find command, which return list of files it find on a specific folder, the problem is, when I iterate over the result, I do not have the file names, I only have their full paths (including the name), is there an easy way to use the result item below to provide the file_name in the second command as shown below?

- name: get files
  find:
    paths: /home/me
    file_type: "file"
  register: find_result

- name: Execute docker secret create
  shell: docker secret create <file_name> {{ item.path }}
  run_once: true
  with_items: "{{ find_result.files }}"
question from:https://stackoverflow.com/questions/45564899/extract-filename-from-file-result-in-ansible

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

basename filter?

{{ item.path | basename }}

There are also dirname, realpath, relpath filters.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...