creating logical volume if does not exist

35 views
Skip to first unread message

Brad

unread,
Sep 12, 2018, 8:27:04 AM9/12/18
to Ansible Project
Relatively new to ansible.  Trying to create a logical volume on some RHEL 7 servers.  I have:

- name: make-lv
  lvol
:
    vg
: vg_{{ inventory_hostname_short }}
    lv
: lv_ekb
    size
: 100%FREE
    state
: present

which works fine if the logical volume does not exist, but fails when it does.  How do I tell it not to fail if the logical volume already exists?

Thanks!

cavamagie

unread,
Sep 12, 2018, 8:42:55 AM9/12/18
to ansible...@googlegroups.com
hi can you run with debug?

i use similar

- name: manage_lvm | creating new LVM logical volume(s)
lvol:
vg: "{{ item[0]['vgname'] }}"
lv: "{{ item[1]['lvname'] }}"
size: "{{ item[1]['size'] }}"
shrink: no
opts: "{{ item[1]['opts'] | default('') }}"
state: "present"
become: true
register: lvm
with_subelements:
- "{{ lvm_groups }}"
- lvnames
when: >
((item[0]['create'] is defined
and item[0]['create']) and
(item[1] is defined and
item[1] != 'None') and
(item[1]['create'] is defined and
item[1]['create']))



lvm_groups:
- vgname: root_vg
create: true
lvnames:
- lvname: root_lv
size: 16G
create: true
filesystem: ext4
mount: true
mntp: /
- lvname: tmp_lv
size: 8G
create: true
filesystem: ext4
mount: true
mntp: /tmp
- lvname: var_lv
size: 4G
create: true
filesystem: ext4
mount: true
mntp: /var



--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7f9ec1c9-6ea5-49c6-894a-e05519b54bdb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brad

unread,
Sep 12, 2018, 11:36:24 AM9/12/18
to Ansible Project
I could not get code similar to yours to work.  I did get it to work with these changes:
- name: lv-test
  command
: lvdisplay /dev/vg{{ inventory_hostname_short }}/lv_ekb
 
register: lvdisp

-name: make-lv
  lvol
:

    vg
: vg_{{ inventory_hostname_short }}
    lv
: lv_ekb
    size
: 100%
FREE
    shrink
: no
    state
: present
  become
: true
 
when: lvdisp.rc|int != 0


this seems to be working.  Thanks so much for your help!

cavamagie

unread,
Sep 12, 2018, 11:38:13 AM9/12/18
to ansible...@googlegroups.com
great! you are welcome!

--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages