|
28 | 28 | - {{ user_data }} |
29 | 29 |
|
30 | 30 | - name: create if needed |
31 | | - shell: multipass launch -n {{ item.name }} --disk {{ item.disk }} --mem {{ item.memory }} --cpus {{ item.cpus }} --cloud-init first_setup/cloud-init.yaml |
| 31 | + shell: multipass launch -n {{ item.name }} --disk {{ item.disk }} --mem {{ item.memory }} --cpus {{ item.cpus }} {{ item.launch_extra }} --cloud-init first_setup/cloud-init.yaml |
32 | 32 | when: item.name not in inst_list | map(attribute='inst_name') |
33 | 33 | with_items: "{{ setup_lst }}" |
34 | 34 | - name: new list |
35 | 35 | ansible.builtin.include_tasks: |
36 | 36 | file: multipass_list.yml |
37 | | -- debug: var=inst_list verbosity=3 |
| 37 | +- name: debug new list |
| 38 | + debug: var=inst_list verbosity=3 |
38 | 39 |
|
39 | 40 | - name: build name ip map |
40 | 41 | ansible.builtin.set_fact: |
|
43 | 44 | item.name in inst_list | map(attribute='inst_name') and |
44 | 45 | (inst_list | selectattr("inst_name", "equalto", item.name))| map(attribute='ip_adr4') != [item.ip4 ] |
45 | 46 | with_items: "{{ setup_lst }}" |
46 | | -- debug: var=ip_2_change verbosity=3 |
| 47 | +- name: debug ip_2_change |
| 48 | + debug: var=ip_2_change verbosity=3 |
47 | 49 | when: ip_2_change is defined |
48 | 50 |
|
49 | 51 | - name: "Replace line in file inventory.yml" |
|
52 | 54 | regexp: "(^\\s*ansible_host:\\s*)(\"{{ item.aip | regex_escape() }}\")(.*)$" |
53 | 55 | replace: "\\1\"{{item.mip}}\"" |
54 | 56 | with_items: "{{ ip_2_change }}" |
55 | | - when: ip_2_change is defined |
56 | | -- name: change etc hosts |
| 57 | + when: ip_2_change is defined |
| 58 | + |
| 59 | +- name: remove mylyn vm from etc hosts |
57 | 60 | become: true |
58 | 61 | become_user: root |
59 | | - ansible.builtin.replace: |
| 62 | + ansible.builtin.lineinfile: |
60 | 63 | path: /etc/hosts |
61 | | - regexp: "{{item.aip | regex_escape()}}(\\s+.*)?$" |
62 | | - replace: "{{item.mip}}\\1" |
| 64 | + regexp: "{{'^.*'+ item.aname +'.*' }}" |
| 65 | + state: absent |
63 | 66 | with_items: "{{ ip_2_change }}" |
64 | | - when: ip_2_change is defined and (not item.aip is search("192.168.64.x")) |
65 | | -- name: append etc hosts |
| 67 | + when: ip_2_change is defined |
| 68 | + |
| 69 | +- name: add mylyn vm to etc hosts} |
66 | 70 | become: true |
67 | 71 | become_user: root |
68 | 72 | ansible.builtin.lineinfile: |
69 | 73 | path: /etc/hosts |
70 | | - line: "{{ item.mip }} {{hostvars[item.aname].default_etc_hosts}}" |
71 | | - insertafter: EOF |
| 74 | + line: "{{ item.mip + ' ' + hostvars[item.aname].default_etc_hosts }}" |
| 75 | + state: present |
72 | 76 | with_items: "{{ ip_2_change }}" |
73 | | - when: ip_2_change is defined and (item.aip is search("192.168.64.x")) |
| 77 | + when: ip_2_change is defined |
0 commit comments