Skip to contentSkip to conversation

devconfig: install-deps is skipped in some configurations

RFC PATCH In review [email protected] 3 participants 3 messages Jan 28, 2025 – Jan 29, 2025

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 devconfig: install-deps is skipped in some configurations

From: Chuck Lever <[email protected]>

A recent commit replaced import_tasks with include_tasks in a few steps in the devconfig playbook.

The Ansible "import_tasks" documentation says:

Quoted 2 lines

Tags are not interpreted for this action, they are applied to the imported tasks

Revert some of the import_tasks conversions to ensure those steps are run according to the command-line tag settings.

For the original problem that I tripped on, add tags to ensure those sub-steps get run as needed.

Fixes e1a41cd9d4ee ("devconfig: Replace import_tasks with include_tasks")
---
 playbooks/roles/devconfig/tasks/main.yml | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
playbooks/roles/devconfig/tasks/main.yml +4 -3
index 51b890375215..84c5fa1f1cf8 100644
@@ -32,9 +32,10 @@
 # Distro specific
 - name: Install dependencies
   ansible.builtin.include_tasks: install-deps/main.yml
+  tags: ['vars', 'vars_simple']
 
 - name: Configure custom repositories and install packages
-  ansible.builtin.include_tasks: config-custom-repos-and-packages/main.yml
+  ansible.builtin.import_tasks: config-custom-repos-and-packages/main.yml
   when:
     - ansible_facts['os_family']|lower == 'redhat'
 
@@ -447,7 +448,7 @@
   tags: [ 'console' ]
 
 - name: Update your boot GRUB file if necessary
-  ansible.builtin.include_tasks: update-grub/main.yml
+  ansible.builtin.import_tasks: update-grub/main.yml
   when:
     - grub2_config_file.stat.exists
     - devconfig_enable_console|bool
@@ -637,7 +638,7 @@
   tags: [ 'sysctl' ]
 
 - name: Rev the kernel to the latest distribution kotd
-  ansible.builtin.include_tasks: kotd-rev-kernel/main.yml
+  ansible.builtin.import_tasks: kotd-rev-kernel/main.yml
   when:
     - devconfig_enable_kotd|bool
   tags: [ 'kotd' ]
Signature · 1 line
2.48.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · On Tue, Jan 28, 2025 at 12:32:33PM -0500, [email protected] wrote:

From: Chuck Lever <[email protected]>

A recent commit replaced import_tasks with include_tasks in a few steps in the devconfig playbook.

The Ansible "import_tasks" documentation says:

Quoted 2 lines

Tags are not interpreted for this action, they are applied to the imported tasks

They seem to not recommend mixing tags with imports and includes [1] due to tag inheritance differences between them.

[1] https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_tags.html#tags

If I'm reading correctly, include_tasks require the tag to be present at both levels, the include_tasks 'task' and at every task we want to be executed.

This is not needed when import_tasks is used as all imported 'tasks' inherit the top level tag and tag annotation is not required.

We tend to be explicit with tags so, we probably want to stick with include_tasks, right?

Quoted 10 lines

Revert some of the import_tasks conversions to ensure those steps are run according to the command-line tag settings.

For the original problem that I tripped on, add tags to ensure those sub-steps get run as needed.

Fixes e1a41cd9d4ee ("devconfig: Replace import_tasks with include_tasks")

This is the wrong commit hash. It points to a forked repository.

Should be ec9a34e (ec9a34eb6b8eb150822b264747ebd053dc1d8663) instead.

Quoted 10 lines
---
 playbooks/roles/devconfig/tasks/main.yml | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
playbooks/roles/devconfig/tasks/main.yml +0 -0
index 51b890375215..84c5fa1f1cf8 100644

playbooks/roles/devconfig/tasks/main.yml line 35

Quoted 4 lines
playbooks/roles/devconfig/tasks/main.yml +1 -0
@@ -32,9 +32,10 @@
 # Distro specific
 - name: Install dependencies
   ansible.builtin.include_tasks: install-deps/main.yml
+  tags: ['vars', 'vars_simple']

Keeping include_tasks enforces us to explicitly tag this include_tasks task with the right tag, but also every task in install-deps.

journal-server target is executed with vars_simple,journal tags, so the include will now be evaluated true. Then, install/deps/main.yml has a debian setup task to include_tasks in debian/main.yml and properly using vars_simple tag. Then, debian/main.yml will only execute tasks properly tagged with vars_simple or journal. So, "Install systemd-journal-remote" is run and rest of the tasks are skipped.

playbooks/roles/devconfig/tasks/main.yml line 40

Quoted 6 lines
playbooks/roles/devconfig/tasks/main.yml +1 -1
 - name: Configure custom repositories and install packages
-  ansible.builtin.include_tasks: config-custom-repos-and-packages/main.yml
+  ansible.builtin.import_tasks: config-custom-repos-and-packages/main.yml
   when:
     - ansible_facts['os_family']|lower == 'redhat'

If my reading above is correct, this import will be skipped when tags are applied to the ansible-playbook command. At this moment, only devconfig, sysctl-tunings targets will trigger this path.

playbooks/roles/devconfig/tasks/main.yml line 454

Quoted 10 lines
playbooks/roles/devconfig/tasks/main.yml +1 -1
@@ -447,7 +448,7 @@
   tags: [ 'console' ]
 
 - name: Update your boot GRUB file if necessary
-  ansible.builtin.include_tasks: update-grub/main.yml
+  ansible.builtin.import_tasks: update-grub/main.yml
   when:
     - grub2_config_file.stat.exists
     - devconfig_enable_console|bool

Same here, only triggered with devconfig and sysctl-tunings.

playbooks/roles/devconfig/tasks/main.yml line 644

Quoted 9 lines
playbooks/roles/devconfig/tasks/main.yml +1 -1
@@ -637,7 +638,7 @@
   tags: [ 'sysctl' ]
 
 - name: Rev the kernel to the latest distribution kotd
-  ansible.builtin.include_tasks: kotd-rev-kernel/main.yml
+  ansible.builtin.import_tasks: kotd-rev-kernel/main.yml
   when:
     - devconfig_enable_kotd|bool
   tags: [ 'kotd' ]

This will only be executed for kotd-dev, kotd-baseline and kotd targets.

Quoted 3 lines
Signature · 1 line
2.48.1

I can't verify the other paths being reverted but they look good to me.

Also, the changes here fix the issue in kdevops CI (tested locally).

#2 lore raw
Quoted 106 lines · Daniel Gomez
Quoted 9 lines · On Tue, Jan 28, 2025 at 12:32:33PM -0500, [email protected] wrote:

From: Chuck Lever <[email protected]>

A recent commit replaced import_tasks with include_tasks in a few steps in the devconfig playbook.

The Ansible "import_tasks" documentation says:

Quoted 2 lines

Tags are not interpreted for this action, they are applied to the imported tasks

They seem to not recommend mixing tags with imports and includes [1] due to tag inheritance differences between them.

[1] https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_tags.html#tags

If I'm reading correctly, include_tasks require the tag to be present at both levels, the include_tasks 'task' and at every task we want to be executed.

This is not needed when import_tasks is used as all imported 'tasks' inherit the top level tag and tag annotation is not required.

We tend to be explicit with tags so, we probably want to stick with include_tasks, right?

Quoted 10 lines

Revert some of the import_tasks conversions to ensure those steps are run according to the command-line tag settings.

For the original problem that I tripped on, add tags to ensure those sub-steps get run as needed.

Fixes e1a41cd9d4ee ("devconfig: Replace import_tasks with include_tasks")

This is the wrong commit hash. It points to a forked repository.

Should be ec9a34e (ec9a34eb6b8eb150822b264747ebd053dc1d8663) instead.

Quoted 10 lines
---
  playbooks/roles/devconfig/tasks/main.yml | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
playbooks/roles/devconfig/tasks/main.yml +0 -0
index 51b890375215..84c5fa1f1cf8 100644

playbooks/roles/devconfig/tasks/main.yml line 35

Quoted 4 lines
playbooks/roles/devconfig/tasks/main.yml +1 -0
@@ -32,9 +32,10 @@
  # Distro specific
  - name: Install dependencies
    ansible.builtin.include_tasks: install-deps/main.yml
+  tags: ['vars', 'vars_simple']

Keeping include_tasks enforces us to explicitly tag this include_tasks task with the right tag, but also every task in install-deps.

journal-server target is executed with vars_simple,journal tags, so the include will now be evaluated true. Then, install/deps/main.yml has a debian setup task to include_tasks in debian/main.yml and properly using vars_simple tag. Then, debian/main.yml will only execute tasks properly tagged with vars_simple or journal. So, "Install systemd-journal-remote" is run and rest of the tasks are skipped.

playbooks/roles/devconfig/tasks/main.yml line 40

Quoted 6 lines
playbooks/roles/devconfig/tasks/main.yml +1 -1
  - name: Configure custom repositories and install packages
-  ansible.builtin.include_tasks: config-custom-repos-and-packages/main.yml
+  ansible.builtin.import_tasks: config-custom-repos-and-packages/main.yml
    when:
      - ansible_facts['os_family']|lower == 'redhat'

If my reading above is correct, this import will be skipped when tags are applied to the ansible-playbook command. At this moment, only devconfig, sysctl-tunings targets will trigger this path.

playbooks/roles/devconfig/tasks/main.yml line 454

Quoted 10 lines
playbooks/roles/devconfig/tasks/main.yml +1 -1
@@ -447,7 +448,7 @@
    tags: [ 'console' ]
 
  - name: Update your boot GRUB file if necessary
-  ansible.builtin.include_tasks: update-grub/main.yml
+  ansible.builtin.import_tasks: update-grub/main.yml
    when:
      - grub2_config_file.stat.exists
      - devconfig_enable_console|bool

Same here, only triggered with devconfig and sysctl-tunings.

playbooks/roles/devconfig/tasks/main.yml line 644

Quoted 9 lines
playbooks/roles/devconfig/tasks/main.yml +1 -1
@@ -637,7 +638,7 @@
    tags: [ 'sysctl' ]
 
  - name: Rev the kernel to the latest distribution kotd
-  ansible.builtin.include_tasks: kotd-rev-kernel/main.yml
+  ansible.builtin.import_tasks: kotd-rev-kernel/main.yml
    when:
      - devconfig_enable_kotd|bool
    tags: [ 'kotd' ]

This will only be executed for kotd-dev, kotd-baseline and kotd targets.

Quoted 3 lines
Signature · 1 line
2.48.1
Quoted 5 lines

I can't verify the other paths being reverted but they look good to me.

Also, the changes here fix the issue in kdevops CI (tested locally).

Thank you for confirming that. May I add Tested-by: Daniel ... as well?

I will correct the Fixes: tag before committing.

Signature · 1 line
Chuck Lever