ansible-practice/filemap.yaml
2023-11-08 17:37:18 +00:00

30 lines
783 B
YAML

---
- name: showing map
hosts: all
gather_facts: no
become: yes
vars:
- basedir: /var/www/html
tasks:
- name: showing basedir
debug:
var: basedir
- name: showing files in basedir
find:
paths: "{{ basedir }}"
recurse: yes
register: basedir_files
- name: showing current variable contents to understand why we need map
debug:
var: basedir_files
- name: show files based on map attribute path without list - will show error
set_fact:
webfiles: "{{ basedir_files['files'] | map(attribute='path') }}"
- debug:
var: webfiles
- name: show files based on map attribute with list
set_fact:
webfileslist: "{{ basedir_files['files'] | map(attribute='path') | list }}"
- debug:
var: webfileslist