Hello,
I'm pretty new in ansible, so excuse me for this (stupid?) question, but it 
bothers me.

I'm trying to set up LVM on the remote host with ansible.

Here is my role:

---
- name: install lvm2
  yum:
    name: "{{ item }}"
    state: present
  with_items:
    - lvm2
  tags:
    - install

- name: select a drive for LVM
  shell: "fdisk -l |grep vdb | awk '{print $2}'"
  register: drive_for_lvm
  tags:
    - configure

- set_fact:
    drive_for_lvm: "{{ drive_for_lvm.stdout_lines }}"
  tags:
    - configure

- set_fact:
    drive_for_lvm: "{{ drive_for_lvm|replace(':','') }}"
  tags:
    - configure

############################## ADD LVM ###########################

- name: create VG
  lvg:
    vg: vg_test
    pvs: "{{ drive_for_lvm }}"
    pesize: 16
  tags:
    - configure

- name: create LV
  lvol:
    vg: vg_test
    lv: lv_test
    size: 100%FREE
    pvs: "{{ drive_for_lvm }}"
  tags:
    - configure


When I execute it, I've got this:

root@ubuntu-latest:~/ansible# ansible-playbook -i group_vars/ playbook.yml 
--skip-tags=install

PLAY [test] 
********************************************************************************************************************************

TASK [lvm : select a drive for LVM] 
********************************************************************************************************
changed: [docker2]

TASK [lvm : set_fact] 
**********************************************************************************************************************
ok: [docker2]

TASK [lvm : set_fact] 
**********************************************************************************************************************
ok: [docker2]

TASK [lvm : create VG] 
*********************************************************************************************************************
changed: [docker2]

TASK [lvm : create LV] 
*********************************************************************************************************************
fatal: [docker2]: FAILED! => {"changed": false, "err": "  Physical Volume 
\"[/dev/vdb]\" not found in Volume Group \"vg_test\".\n", "msg": "Creating 
logical volume 'lv_test' failed", "rc": 5}


Then, I verified the host called "docker2" if it contains PVS /dev/vdb (and 
it does).

[root@docker2 ~]# pvs |grep vdb
  /dev/vdb   vg_test lvm2 a--   4.98g 4.98g



So why ansible says that there is no such physical volume?


I finally edited main.yml inside the role (just commented out pvs section 
in last task):

- name: create VG
  lvg:
    vg: vg_test
    pvs: "{{ drive_for_lvm }}"
    pesize: 16
  tags:
    - configure

- name: create LV
  lvol:
    vg: vg_test
    lv: lv_test
    size: 100%FREE
#    pvs: "{{ drive_for_lvm }}"
  tags:
    - configure



And it works as expected.. Can somebody explain the difference? It is a bug 
or what?

Best regards!


-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/62461c95-5580-4828-b97e-9feb31d48e31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to