Add explicit become: true to apply-manifests kubectl tasks

These tasks set become_user without a task-level become, tripping
ansible-lint's partial-become rule. become is already enabled globally via
ansible_become in group_vars/all.yaml, so the tasks already escalate to the
ansible user — but that is invisible to the linter (and to anyone reading the
task in isolation). Make it explicit with become: true alongside become_user.

Behavior-neutral: verified with ansible-playbook -vvv that the escalation
target is unchanged (sudo -u ansible; chown ansible on the temp files), so
kubectl still runs as the ansible user that owns ~/.kube/config.
This commit is contained in:
cyberops7
2026-07-02 00:18:43 -06:00
parent 9452c8be52
commit fc761c1952

View File

@@ -6,6 +6,7 @@
retries: 120 retries: 120
delay: 10 delay: 10
changed_when: true changed_when: true
become: true
become_user: "{{ ansible_user }}" become_user: "{{ ansible_user }}"
when: inventory_hostname == groups['servers'][0] when: inventory_hostname == groups['servers'][0]
@@ -13,6 +14,7 @@
- name: Apply metallb namespace - name: Apply metallb namespace
ansible.builtin.command: ansible.builtin.command:
cmd: kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/namespace.yaml cmd: kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/namespace.yaml
become: true
become_user: "{{ ansible_user }}" become_user: "{{ ansible_user }}"
changed_when: true changed_when: true
when: inventory_hostname == groups['servers'][0] when: inventory_hostname == groups['servers'][0]
@@ -21,6 +23,7 @@
- name: Apply metallb manifest - name: Apply metallb manifest
ansible.builtin.command: ansible.builtin.command:
cmd: kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/{{ metallb_version }}/config/manifests/metallb-native.yaml cmd: kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/{{ metallb_version }}/config/manifests/metallb-native.yaml
become: true
become_user: "{{ ansible_user }}" become_user: "{{ ansible_user }}"
changed_when: true changed_when: true
when: inventory_hostname == groups['servers'][0] when: inventory_hostname == groups['servers'][0]
@@ -30,6 +33,7 @@
ansible.builtin.command: ansible.builtin.command:
cmd: "kubectl wait --namespace metallb-system --for=condition=ready pod --selector=component=controller --timeout=1800s" cmd: "kubectl wait --namespace metallb-system --for=condition=ready pod --selector=component=controller --timeout=1800s"
changed_when: true changed_when: true
become: true
become_user: "{{ ansible_user }}" become_user: "{{ ansible_user }}"
when: inventory_hostname == groups['servers'][0] when: inventory_hostname == groups['servers'][0]
@@ -47,6 +51,7 @@
- name: Apply metallb L2 Advertisement - name: Apply metallb L2 Advertisement
ansible.builtin.command: ansible.builtin.command:
cmd: kubectl apply -f /home/{{ ansible_user }}/l2advertisement.yaml cmd: kubectl apply -f /home/{{ ansible_user }}/l2advertisement.yaml
become: true
become_user: "{{ ansible_user }}" become_user: "{{ ansible_user }}"
changed_when: true changed_when: true
when: inventory_hostname == groups['servers'][0] when: inventory_hostname == groups['servers'][0]
@@ -65,6 +70,7 @@
- name: Apply metallb ipppool - name: Apply metallb ipppool
ansible.builtin.command: ansible.builtin.command:
cmd: kubectl apply -f /home/{{ ansible_user }}/ippool.yaml cmd: kubectl apply -f /home/{{ ansible_user }}/ippool.yaml
become: true
become_user: "{{ ansible_user }}" become_user: "{{ ansible_user }}"
changed_when: true changed_when: true
when: inventory_hostname == groups['servers'][0] when: inventory_hostname == groups['servers'][0]