From bf9ec2e78cece2db082419434d5ecc3125e1d25e Mon Sep 17 00:00:00 2001 From: "ansible-code-bot[bot]" <145416087+ansible-code-bot[bot]@users.noreply.github.com> Date: Mon, 30 Jun 2025 13:50:55 +0000 Subject: [PATCH] Fix ansible code bot rule violations --- examples/filters.yml | 31 +++++++++++------------ examples/selectattr_map.yml | 35 ++++++++++++------------- examples/workshop_jinja2_filters.yml | 38 +++++++++++++++------------- hello.yml | 13 +++++----- 4 files changed, 60 insertions(+), 57 deletions(-) diff --git a/examples/filters.yml b/examples/filters.yml index 5382e73..e456c1a 100644 --- a/examples/filters.yml +++ b/examples/filters.yml @@ -6,42 +6,41 @@ hosts: rhel9vm gather_facts: false vars: - test: 123 + test: 123 tasks: - - name: Create var which is mandatory - debug: - msg: "This var should be mandatory {{ test | mandatory }}" + ansible.builtin.debug: + msg: This var should be mandatory {{ test | mandatory }} - name: Create users with optionan homedir become: true - user: + ansible.builtin.user: name: "{{ item.name }}" shell: /bin/bash groups: wheel - append: yes + append: true home: "{{ item.homedir | default(omit) }}" loop: - name: james homedir: /opt/james - name: toni - name: pepe - + - name: Playing with selectattr hosts: localhost become: false vars: - hosts: - - name: bastion - ip: - - 172.25.250.254 - - 172.25.252.1 - - name: classroom - ip: - - 172.25.252.254 + hosts: + - name: bastion + ip: + - 172.25.250.254 + - 172.25.252.1 + - name: classroom + ip: + - 172.25.252.254 tasks: - name: Debug using selectattr the 'name' elements from the list of dictionaries in 'hosts' ansible.builtin.debug: msg: - - "{{ hosts | selectattr('name', '==', 'bastion')| map(attribute='ip') }}" + - "{{ hosts | selectattr('name', '==', 'bastion') | map(attribute='ip') }}" diff --git a/examples/selectattr_map.yml b/examples/selectattr_map.yml index b5b35c2..fb3ced7 100644 --- a/examples/selectattr_map.yml +++ b/examples/selectattr_map.yml @@ -1,17 +1,18 @@ -- name: Playing with selectattr - hosts: localhost - become: false - vars: - hosts: - - name: bastion - ip: - - 172.25.250.254 - - 172.25.252.1 - - name: classroom - ip: - - 172.25.252.254 - tasks: - - name: Debug using selectattr the 'name' elements from the list of dictionaries in 'hosts' - ansible.builtin.debug: - msg: - - "{{ hosts | selectattr('name', '==', 'bastion')| map(attribute='ip') }}" +--- +- name: Playing with selectattr + hosts: localhost + become: false + vars: + hosts: + - name: bastion + ip: + - 172.25.250.254 + - 172.25.252.1 + - name: classroom + ip: + - 172.25.252.254 + tasks: + - name: Debug using selectattr the 'name' elements from the list of dictionaries in 'hosts' + ansible.builtin.debug: + msg: + - "{{ hosts | selectattr('name', '==', 'bastion') | map(attribute='ip') }}" diff --git a/examples/workshop_jinja2_filters.yml b/examples/workshop_jinja2_filters.yml index 320ae9f..d84631d 100644 --- a/examples/workshop_jinja2_filters.yml +++ b/examples/workshop_jinja2_filters.yml @@ -1,7 +1,7 @@ --- - name: Workshop using Jinja2 fitlers hosts: serverb - become: true + become: true vars: expected_user: consultant1 tasks: @@ -9,16 +9,16 @@ ansible.builtin.slurp: src: "{{ item }}" loop: - - /etc/passwd - - /etc/shadow - - /etc/group + - /etc/passwd + - /etc/shadow + - /etc/group register: slurped_files - + - name: Set content fact vars: line_separator: "\n" ansible.builtin.set_fact: - etc_passwd: >- + etc_passwd: >- {{ slurped_files['results'] | selectattr('source', '==', '/etc/passwd') | map(attribute='content') | first | b64decode | split(line_separator) }} @@ -26,16 +26,14 @@ {{ slurped_files['results'] | selectattr('source', '==', '/etc/shadow') | map(attribute='content') | first | b64decode | split(line_separator) }} - etc_group: >- - {{ slurped_files['results'] | - selectattr('source', '==', '/etc/group') | map(attribute='content') | - first | b64decode | split(line_separator) }} - + etc_group: >- + {{ slurped_files['results'] | selectattr('source', '==', '/etc/group') | map(attribute='content') | first | b64decode | split(line_separator) }} + - name: Debug slurped files ansible.builtin.debug: msg: "{{ etc_passwd }}" verbosity: 2 - + - name: Set passwd_line_match fact vars: line_search: "^{{ expected_user }}:" @@ -43,7 +41,8 @@ {% for LINE in etc_passwd -%} {% if LINE | regex_search(line_search) -%} {{ LINE }} - {%- endif %} + {%- endif %} + {%- endfor %} ansible.builtin.debug: var: passwd_line_match @@ -55,11 +54,12 @@ {% for LINE in etc_shadow -%} {% if LINE | regex_search(line_search) -%} {{ LINE }} - {%- endif %} + {%- endif %} + {%- endfor %} ansible.builtin.debug: var: shadow_line_match - + - name: Set group_line_match fact vars: line_search: "^{{ expected_user }}:" @@ -67,19 +67,21 @@ {% for LINE in etc_group -%} {% if LINE | regex_search(line_search) -%} {{ LINE }} - {%- endif %} + {%- endif %} + {%- endfor %} ansible.builtin.debug: var: group_line_match - name: Set aux_group_line_match fact vars: - line_search: ":{{ expected_user }}" + line_search: :{{ expected_user }} aux_group_line_match: >- {% for LINE in etc_group -%} {% if LINE | regex_search(line_search) -%} {{ LINE }} - {%- endif %} + {%- endif %} + {%- endfor %} ansible.builtin.debug: var: aux_group_line_match diff --git a/hello.yml b/hello.yml index 71e3edd..046f8b7 100644 --- a/hello.yml +++ b/hello.yml @@ -3,10 +3,11 @@ hosts: all tasks: - name: Hello Message - debug: - msg: "Hello World" - - name: Hostname of machine - shell: hostname -f + ansible.builtin.debug: + msg: Hello World + + - name: Hostname of machine register: output - - debug: - msg: "This host is {{ output.stdout }}" + ansible.builtin.command: hostname -f + - ansible.builtin.debug: + msg: This host is {{ output.stdout }}