31d18f7efab702929182be46d82429f7662f7f52
[icn.git] / deploy / metal3-vm / vm-setup / roles / virtbmc / tasks / setup_tasks.yml
1 ---
2
3 - name: Create VirtualBMC directories
4   file:
5     path: "{{ item }}"
6     state: directory
7     mode: 0750
8     owner: root
9     group: root
10   with_items:
11     - "/etc/virtualbmc"
12     - "/var/log/virtualbmc"
13   become: true
14
15 - name: Create VirtualBMC configuration file
16   copy:
17     mode: 0750
18     dest: "/etc/virtualbmc/virtualbmc.conf"
19     content: |
20       [default]
21       config_dir=/root/.vbmc
22       [log]
23       logfile=/var/log/virtualbmc/virtualbmc.log
24       debug=True
25       [ipmi]
26       session_timout=20
27   become: true
28
29 - name: get virthost non_root_user userid
30   command: id -u {{ non_root_user }}
31   register: non_root_user_uid
32
33 - name: set fact on non_root_user_uid
34   set_fact:
35     non_root_user_uid: "{{ non_root_user_uid.stdout }}"
36
37 # The first network defined with an address will be used for vbmc access.
38 - name: set vbmc address if there is a (nat) network defined with an address
39   set_fact:
40     vbmc_address: "{{ networks|selectattr('address', 'defined')|map(attribute='address')|list|first }}"
41   when: networks|selectattr('address', 'defined')|map(attribute='name')|list|length > 0
42
43 # The connection uri is slightly different when using qemu:///system
44 # and requires the root user.
45 - name: set qemu uri for qemu:///system usage
46   set_fact:
47     vbmc_libvirt_uri: "qemu+ssh://root@{{ vbmc_address }}/system?&keyfile=/root/.ssh/id_rsa_virt_power&no_verify=1&no_tty=1"
48   when: libvirt_uri == "qemu:///system"
49
50 - name: set qemu uri for qemu:///session usage
51   set_fact:
52     vbmc_libvirt_uri: "qemu+ssh://{{ non_root_user }}@{{ vbmc_address }}/session?socket=/run/user/{{ non_root_user_uid }}/libvirt/libvirt-sock&keyfile=/root/.ssh/id_rsa_virt_power&no_verify=1&no_tty=1"
53   when: vbmc_libvirt_uri is not defined
54
55 - name: Start the Virtual BMCs (virtualbmc >= 1.4.0+) on Redhat-family OSes
56   service:
57     name: "virtualbmc"
58     state: started
59     enabled: true
60   when:
61     - ansible_os_family == "RedHat"
62   become: true
63
64 - name: Start the Virtual BMCs (virtualbmc >= 1.4.0+) on ubuntu
65   shell: vbmcd || true
66   when:
67     - ansible_facts['distribution'] == "Ubuntu"
68   become: true
69
70
71 - name: Create the Virtual BMCs
72   command: "vbmc add {{ item.name }} --port {{ item.virtualbmc_port }} --libvirt-uri {{ vbmc_libvirt_uri }}"
73   args:
74     creates: /root/.vbmc/{{ item.name }}/config
75   with_items: "{{ vm_nodes }}"
76   become: true
77   environment:
78     PATH: "{{ ansible_env.PATH }}:/usr/local/bin"
79
80 - name: Start the Virtual BMCs
81   script: vbmc_start.sh {{ item.name }}
82   with_items: "{{ vm_nodes }}"
83   become: true