File tree 8 files changed +105
-18
lines changed
8 files changed +105
-18
lines changed Original file line number Diff line number Diff line change @@ -16,16 +16,22 @@ jobs:
16
16
- name : Checkout
17
17
uses : actions/checkout@v3
18
18
19
+ - name : Install uv
20
+ uses : astral-sh/setup-uv@v5
21
+
19
22
- name : Set up Python
20
- uses : actions/setup-python@v2
21
- with :
22
- python-version : ' 3.x'
23
+ run : uv python install
23
24
24
- - name : Install dependencies.
25
- run : pip install -r requirements.txt
25
+ - name : Install dependencies
26
+ run : |
27
+ uv -q venv --allow-existing --seed .venv
28
+ . .venv/bin/activate
29
+ uv -q pip install -r requirements.txt
26
30
27
31
- name : Run ansible-lint
28
- run : " ansible-lint"
32
+ run : |
33
+ . .venv/bin/activate
34
+ ansible-lint
29
35
30
36
molecule :
31
37
strategy :
@@ -36,15 +42,20 @@ jobs:
36
42
- name : Checkout
37
43
uses : actions/checkout@v3
38
44
45
+ - name : Install uv
46
+ uses : astral-sh/setup-uv@v5
47
+
39
48
- name : Set up Python
40
- uses : actions/setup-python@v2
41
- with :
42
- python-version : ' 3.x'
49
+ run : uv python install
43
50
44
51
- name : Install dependencies.
45
52
run : |
46
- pip install -r requirements.txt
53
+ uv -q venv --allow-existing --seed .venv
54
+ . .venv/bin/activate
55
+ uv -q pip install -r requirements.txt
47
56
ansible-galaxy install -r requirements.yml
48
57
49
58
- name : Run molecule
50
- run : molecule test -p ${{ matrix.os }}
59
+ run : |
60
+ . .venv/bin/activate
61
+ molecule test -p ${{ matrix.os }}
Original file line number Diff line number Diff line change 1
1
---
2
2
php :
3
+ repository :
4
+ apt :
5
+ enabled : no
6
+ repository : >-
7
+ {%- if ansible_distribution == 'Ubuntu' -%}
8
+ https://ppa.launchpadcontent.net/ondrej/php/ubuntu
9
+ {%- else -%}
10
+ https://packages.sury.org/php/
11
+ {%- endif -%}
12
+ key_url : >-
13
+ {%- if ansible_distribution == 'Ubuntu' -%}
14
+ https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xb8dc7e53946656efbce4c1dd71daeaab4ad4cab6
15
+ {%- else -%}
16
+ https://packages.sury.org/apt.gpg
17
+ {%- endif -%}
3
18
version : " {{ ansible_local.php.version }}"
4
19
prefix : " {{ ansible_local.php.prefix }}"
5
20
xdebug :
Original file line number Diff line number Diff line change @@ -31,11 +31,12 @@ def get_os_family(self) -> str:
31
31
def get_php_version (self ) -> str :
32
32
os_family = self .get_os_family ()
33
33
if os_family == "debian" :
34
- command = 'apt-cache search --names-only "^php[0-9].[0-9]$" | grep -o "[0-9]\\ .[0-9]"'
34
+ command = 'apt-cache search --names-only "^php[0-9].[0-9]$" | grep -o "[0-9]\\ .[0-9]" | sort -V | tail -n 1 '
35
35
else :
36
36
command = "php -r 'echo phpversion();' | grep -o '[0-9]\\ .[0-9]' | head -n1"
37
37
command_output = subprocess .run (command , shell = True , capture_output = True )
38
- if len (command_output .stdout ) > 0 :
38
+ clean_output = command_output .stdout .decode ().strip ()
39
+ if re .match (r"[0-9]+\.[0-9]" , clean_output ):
39
40
return command_output .stdout .decode ().strip ()
40
41
else :
41
42
raise OSError (f"Error detecting the PHP version: command_output.stderr.decode()" )
Original file line number Diff line number Diff line change 10
10
proserver_user : yes
11
11
nginx :
12
12
default_server : no
13
+ php :
14
+ repository :
15
+ apt :
16
+ enabled : yes
13
17
tasks :
14
18
- name : " Include ansible-proserver-php"
15
19
ansible.builtin.include_role :
Original file line number Diff line number Diff line change
1
+ ---
2
+ - name : Install python3-debian package with apt
3
+ ansible.builtin.apt :
4
+ name : python3-debian
5
+ update_cache : yes
6
+
7
+ - name : Remove the legacy apt repository
8
+ when : php.repository.apt.enabled
9
+ ansible.builtin.file :
10
+ dest : /etc/apt/sources.list.d/php.list
11
+ state : absent
12
+
13
+ - name : Ensure the third-party PHP repository is {{ 'present' if php.repository.apt.enabled else 'absent' }}
14
+ changed_when : " 'molecule-idempotence-notest' not in ansible_skip_tags"
15
+ register : php_repository_added
16
+ ansible.builtin.deb822_repository :
17
+ name : php
18
+ uris : " {{ php.repository.apt.repository }}"
19
+ signed_by : " {{ php.repository.apt.key_url }}"
20
+ types : [deb]
21
+ components : [main]
22
+ suites : " {{ ansible_distribution_release }}"
23
+ state : " {{ 'present' if php.repository.apt.enabled else 'absent' }}"
24
+ enabled : " {{ php.repository.apt.enabled }}"
25
+
26
+ - name : Update apt cache (Debian-based)
27
+ when : php_repository_added.changed
28
+ changed_when : no
29
+ ansible.builtin.apt :
30
+ update_cache : yes
31
+
32
+ - name : Reload facts
33
+ when : php_repository_added.changed
34
+ check_mode : no
35
+ changed_when : no
36
+ ansible.builtin.setup : {}
Original file line number Diff line number Diff line change 3
3
ansible.builtin.user :
4
4
name : proserver
5
5
6
- - name : Install PHP and extensions
6
+ - name : Install PHP {{ php.version }} and extensions
7
7
notify : Restart PHP-FPM
8
8
ansible.builtin.apt :
9
9
name : >-
10
10
{{
11
- ['php-fpm'] + php.install_extensions.items() |
11
+ ['php' + (php.version if php.repository.apt.enabled else '') + ' -fpm'] + php.install_extensions.items() |
12
12
selectattr('1', 'eq', true)|map(attribute='0') |
13
- map('regex_replace', '^', 'php-') |
13
+ map('regex_replace', '^', 'php' + (php.version if php.repository.apt.enabled else '') + ' -') |
14
14
list + (['composer'] if php.install_composer else [])
15
15
}}
16
+
17
+ - name : List all packages belonging to other PHP versions
18
+ changed_when : no
19
+ check_mode : no
20
+ register : previous_php_packages
21
+ failed_when : previous_php_packages.failed and previous_php_packages.stderr != ""
22
+ ansible.builtin.shell :
23
+ cmd : |
24
+ dpkg -l php\* | awk '/^[hi]i/{print $2}' | grep "php[0-9]\\.[0-9]" | grep -v {{ php.version }}
25
+
26
+ - name : Ensure all non-{{ php.version }} PHP packages are uninstalled
27
+ when : previous_php_packages.stdout != ""
28
+ ansible.builtin.apt :
29
+ package : " {{ previous_php_packages.stdout_lines }}"
30
+ state : absent
31
+ update_cache : yes
32
+ autoremove : yes
Original file line number Diff line number Diff line change 2
2
- name : Set the PHP facts
3
3
ansible.builtin.include_tasks : php_fact.yaml
4
4
5
+ - name : Manage apt repo (Ubuntu/Debian)
6
+ when : ansible_os_family == 'Debian'
7
+ ansible.builtin.include_tasks : apt.yaml
8
+
5
9
- name : Install PHP and extensions (Ubuntu/Debian)
6
10
when : ansible_os_family == 'Debian'
7
11
ansible.builtin.include_tasks : install.yaml
Original file line number Diff line number Diff line change 28
28
29
29
- name : Reload facts
30
30
check_mode : no
31
- when : php_template_fact_result.changed
32
- changed_when : yes
31
+ changed_when : no
33
32
ansible.builtin.setup : {}
You can’t perform that action at this time.
0 commit comments