Hello:
On Mon, Feb 17, 2020 at 7:19 PM Barun kumar <[email protected]> wrote:
>
> Hi Disk,
>
> More explanation about playbook, hope you did not chance to see that,
> please check once.
>
>
>
>
>
> cat /tmp/volume.txt #Has list of disk attached to server, which needs
> to excluded
>
> ["xvda", "xvdb", "xvdc", "xvdd", "xvde", "xvdf", "xvdg", "xvdh", "xvdi"]
>
>
>
>
>
> # disk.yml
>
> disk_count.stdout: 2 #number of disk need to add to server.
>
>
>
> - name: Call devicecheck script
>
> shell: |
>
> a1=( "xvda" "xvdb" "xvdc" "xvdd" "xvde" "xvdf" "xvdg" "xvdh" "xvdi"
> "xvdj" "xvdk" "xvdl" "xvdm" "xvdn" "xvdo" "xvdp" "xvdq" "xvdr" "xvds"
> "xvdt" "xvdu" "xvdv" "xvdw" "xvdx" "xvdy" "xvdz")
>
Do you need to do this by using a shell task? I'm not sure how you get the
list of disks which you pretend to filter, but let me know if this approach
works for you:
- name: Set the list of all disks
set_fact:
a1: ["xvda", "xvdb", "xvdc", "xvdd", "xvde", "xvdf", "xvdg",
"xvdh", "xvdi", "xvdj", "xvdk", "xvdl"] #complete the list of all disks here
- name: Import the contents from file as a list
set_fact:
excluded_disks: "{{ lookup('file', 'volume.txt') }}"
- name: Set the list of device names without considering excluded disks
set_fact:
device_name: "{{ device_name | default([]) + [item] }}"
when: item not in excluded_disks
with_items: "{{ a1 }}"
- name: Show the final list of device names
debug:
var: device_name
I assumed you disks to exclude are defined in a volume.txt file. As I don't
know how you get the list of all original disks (which you set in a1
variable within your shell script), I've just defined in an ansible
variable.
This way, there's no need to deal with quoting, because that might be a
little hard to solve, read and troubleshoot.
If you can share more lines from your code or what you pretend to achieve,
maybe we can suggest some better ideas.
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAA3McK8Wq18%2Bv%2BgZkRREXD8JhXhfP_n8ON_0uWCh0bDvPMi5mw%40mail.gmail.com.