0

i would create a playbook that Check configured filesystems for TSM configuration I need to echo "${FS_TSM[@]}" from register: FS_TO_ADD and to conclude it, a conditional must be set to debug the FS_TSM [[ ! -z "${FS_TO_ADD}" ]] && { FS_TSM+=( "${FS_TO_ADD}" } . I think When: statement1 than statement2 is the good but i don't know how to set it to achieve it


  - hosts: all
    vars:
      whitelist:
        - '/bin'
        - '/boot'
      FS_TSM:
        - '/'

    tasks:
      - set_fact:
          mount_point: "{{ansible_facts.mounts | selectattr('fstype', 'match', '^xf+') | map(attribute='mount')}}"
      - debug:
          var: mount_point

        loop: "{{ whitelist }}"
        when: item in mount_point
        register: FS_TO_ADD

the final result of the playbook is to get this output:

/
/boot 
/home
/opt  
/var 
/var
/opt 
/var/tmp
/var/log
/var/log/audit
medisamm
  • 1
  • 1

2 Answers2

0

Not sure what you're getting at, in any case, maybe some inspiration:

- name: Test
  hosts: all
  vars:
    whitelist:
      - /bin
      - /boot
    FS_TSM:
      - /

  tasks:

  - name: Debug
    debug:
      msg: "{{ ansible_facts.mounts | selectattr('fstype', 'match', '^xf+') | map(attribute='mount') | intersect(whitelist) | union(FS_TSM) | list }}"

on my system yields:

ASK [Debug] ***********************************************************************************************************************************************************************************************
ok: [server] => {
    "msg": [
        "/boot",
        "/"
    ]
}
0

@KrisVandenbergh your suggestion is really helpful especially with

intersect(whitelist) | union(FS_TSM) It worked well. Meanwhile i modified my playbook and it gave me what i am looking for:

- set_fact:

mount_point: "{{ansible_facts.mounts | selectattr('fstype', 'match', '^ext+') | map(attribute='mount') | list }}"

vars:

query: "[?mount==whitelist].mount "

- debug:

var: mount_point
medisamm
  • 1
  • 1