configure_libvirt_network.yml 900 B

123456789101112131415161718192021222324252627
  1. ---
  2. - name: Test if libvirt network for openshift already exists
  3. command: "virsh -c {{ libvirt_uri }} net-info {{ libvirt_network }}"
  4. register: net_info_result
  5. changed_when: False
  6. failed_when: "net_info_result.rc != 0 and 'error: Network not found:' not in net_info_result.stderr"
  7. - name: Create a temp directory for the template xml file
  8. command: "/usr/bin/mktemp -d /tmp/openshift-ansible-XXXXXXX"
  9. register: mktemp
  10. when: net_info_result.rc == 1
  11. - name: Create network xml file
  12. template:
  13. src: templates/network.xml
  14. dest: "{{ mktemp.stdout }}/network.xml"
  15. when: net_info_result.rc == 1
  16. - name: Create libvirt network for openshift
  17. command: "virsh -c {{ libvirt_uri }} net-create {{ mktemp.stdout }}/network.xml"
  18. when: net_info_result.rc == 1
  19. - name: Remove the temp directory
  20. file:
  21. path: "{{ mktemp.stdout }}"
  22. state: absent
  23. when: net_info_result.rc == 1