|
13 | 13 | hosts: testbed-manager.testbed.osism.xyz
|
14 | 14 |
|
15 | 15 | vars:
|
16 |
| - repo_path: /home/ubuntu/src/github.com |
17 | 16 | apt_lock_timeout: 300
|
| 17 | + repo_path: /home/ubuntu/src/github.com |
| 18 | + venv_path: /opt/venv |
| 19 | + ansible_galaxy: "{{ venv_path }}/bin/ansible-galaxy" |
18 | 20 |
|
19 | 21 | tasks:
|
20 | 22 | - name: Fail if Ubuntu version is lower than 22.04
|
21 | 23 | ansible.builtin.fail:
|
22 | 24 | msg: "Ubuntu version is {{ ansible_distribution_version }}, see https://osism.tech/docs/advanced-guides/testbed#software for required version."
|
23 | 25 | when: ansible_distribution == "Ubuntu" and ansible_distribution_version < "22.04"
|
24 | 26 |
|
| 27 | + - name: Get current user |
| 28 | + ansible.builtin.user: |
| 29 | + name: "{{ ansible_user }}" |
| 30 | + register: current_user |
| 31 | + |
25 | 32 | - name: Update APT cache and run dist-upgrade
|
26 | 33 | become: true
|
27 | 34 | ansible.builtin.apt:
|
|
39 | 46 | executable: /bin/bash
|
40 | 47 | changed_when: true
|
41 | 48 |
|
42 |
| - - name: Install packages on manager |
| 49 | + - name: Install packages |
43 | 50 | become: true
|
44 | 51 | ansible.builtin.apt:
|
45 | 52 | name:
|
46 | 53 | # The correct package name is linux-generic-hwe-22.04 on Ubuntu 22.04
|
47 | 54 | # and linux-generic-hwe-24.04 on Ubuntu 24.04.
|
48 | 55 | - "linux-generic-hwe-{{ ansible_distribution_version }}"
|
49 | 56 | - python3-netaddr
|
50 |
| - - python3-pip |
51 |
| - update_cache: true |
| 57 | + - python3-venv |
52 | 58 | changed_when: true
|
53 | 59 |
|
54 |
| - - name: Remove existing Ansible package if necessary |
| 60 | + - name: Create venv directory |
55 | 61 | become: true
|
56 |
| - ansible.builtin.apt: |
57 |
| - name: ansible |
58 |
| - state: absent |
| 62 | + ansible.builtin.file: |
| 63 | + owner: "{{ ansible_user }}" |
| 64 | + group: "{{ current_user.group }}" |
| 65 | + path: "{{ venv_path }}" |
| 66 | + state: directory |
| 67 | + mode: 0755 |
59 | 68 |
|
60 |
| - - name: Install ansible-core on manager |
61 |
| - become: true |
62 |
| - ansible.builtin.command: | |
63 |
| - pip3 install --no-cache-dir 'ansible-core>=2.16.0,<2.17.0' |
64 |
| - changed_when: true |
| 69 | + - name: Install ansible-core in venv |
| 70 | + ansible.builtin.pip: |
| 71 | + umask: "0022" |
| 72 | + name: "ansible-core>=2.16.0,<2.17.0" |
| 73 | + state: present |
| 74 | + virtualenv: "{{ venv_path }}" |
| 75 | + virtualenv_command: python3 -m venv |
65 | 76 |
|
66 |
| - - name: Create source directories |
| 77 | + - name: Create directories in /opt/src |
67 | 78 | become: true
|
68 | 79 | ansible.builtin.file:
|
69 | 80 | state: directory
|
70 | 81 | path: "/opt/src/{{ item }}"
|
71 | 82 | recurse: true
|
72 |
| - mode: '0755' |
73 |
| - owner: ubuntu |
| 83 | + mode: 0755 |
| 84 | + owner: "{{ ansible_user }}" |
74 | 85 | with_items:
|
75 | 86 | - osism/ansible-collection-commons
|
76 | 87 | - osism/ansible-collection-services
|
77 | 88 |
|
78 |
| - - name: Copy sources |
| 89 | + - name: Sync sources in /opt/src |
79 | 90 | ansible.posix.synchronize:
|
80 | 91 | src: "{{ repo_path }}/{{ item }}"
|
81 | 92 | delete: true
|
|
89 | 100 | ansible.builtin.file:
|
90 | 101 | state: directory
|
91 | 102 | path: /usr/share/ansible
|
92 |
| - mode: '0755' |
| 103 | + mode: 0755 |
93 | 104 |
|
94 |
| - - name: Install collections |
| 105 | + - name: Install collections from Ansible galaxy |
95 | 106 | become: true
|
96 |
| - ansible.builtin.shell: | |
97 |
| - ansible-galaxy collection install --collections-path /usr/share/ansible/collections ansible.netcommon |
98 |
| - ansible-galaxy collection install --collections-path /usr/share/ansible/collections ansible.posix |
99 |
| - ansible-galaxy collection install --collections-path /usr/share/ansible/collections community.docker |
100 |
| - ansible-galaxy collection install --collections-path /usr/share/ansible/collections /opt/src/osism/ansible-collection-commons |
101 |
| - ansible-galaxy collection install --collections-path /usr/share/ansible/collections /opt/src/osism/ansible-collection-services |
102 |
| - chmod -R +r /usr/share/ansible |
103 |
| - changed_when: true |
| 107 | + ansible.builtin.command: | |
| 108 | + {{ ansible_galaxy }} collection install --collections-path /usr/share/ansible/collections {{ item }} |
| 109 | + register: result |
| 110 | + changed_when: "'was installed successfully' in result.stdout" |
| 111 | + loop: |
| 112 | + - ansible.netcommon |
| 113 | + - ansible.posix |
| 114 | + - community.docker |
| 115 | + |
| 116 | + - name: Install local collections |
| 117 | + become: true |
| 118 | + ansible.builtin.command: | |
| 119 | + {{ ansible_galaxy }} collection install --collections-path /usr/share/ansible/collections /opt/src/osism/{{ item }} |
| 120 | + register: result |
| 121 | + changed_when: "'was installed successfully' in result.stdout" |
| 122 | + loop: |
| 123 | + - ansible-collection-commons |
| 124 | + - ansible-collection-services |
104 | 125 |
|
105 | 126 | - name: Create operator user
|
106 | 127 | hosts: testbed-manager.testbed.osism.xyz
|
|
112 | 133 | operator_authorized_keys:
|
113 | 134 | - "{{ lookup('file', '.id_rsa.' + cloud_env + '.pub') }}"
|
114 | 135 |
|
| 136 | + venv_path: /opt/venv |
| 137 | + ansible_python_interpreter: "{{ venv_path }}/bin/python3" |
| 138 | + |
115 | 139 | roles:
|
116 | 140 | - role: osism.commons.operator
|
| 141 | + |
| 142 | +- name: Run manager part 0 |
| 143 | + hosts: testbed-manager.testbed.osism.xyz |
| 144 | + |
| 145 | + vars: |
| 146 | + operator_user: dragon |
| 147 | + operator_group: dragon |
| 148 | + venv_path: /opt/venv |
| 149 | + |
| 150 | + tasks: |
| 151 | + - name: "Recursively change ownership of {{ venv_path }}" |
| 152 | + become: true |
| 153 | + ansible.builtin.file: |
| 154 | + path: "{{ venv_path }}" |
| 155 | + state: directory |
| 156 | + owner: "{{ operator_user }}" |
| 157 | + group: "{{ operator_group }}" |
| 158 | + recurse: true |
0 commit comments