--- - name: Verify hosts: all gather_facts: true become: true tasks: - name: "Test: file /etc/hosts" block: - name: "Stat file /etc/hosts" ansible.builtin.stat: path: "/etc/hosts" register: stat_etc_hosts - name: "Verify file /etc/hosts" ansible.builtin.assert: that: - stat_etc_hosts.stat.exists - stat_etc_hosts.stat.isreg - stat_etc_hosts.stat.pw_name == 'root' - stat_etc_hosts.stat.gr_name == 'root' - name: "Test: packages pip, vault-cli, yamllint, docker" vars: wanted_up_to_date_list: ["pip", "docker"] wanted_out_of_date_list: ["vault-cli", "yamllint"] block: - name: "Get pip3 up-to-date packages" ansible.builtin.command: "pip3 list -u --format=json" changed_when: false register: pip_updated_packages - name: "Get pip3 out-of-date packages" ansible.builtin.command: "pip3 list -o --format=json" changed_when: false register: pip_outdated_packages - name: "Set fact for pip3 up-to-date packages" ansible.builtin.set_fact: pip3_updated_list: "{{ pip3_updated_list | default({}) | combine({item.name: item.version}) }}" loop: "{{ pip_updated_packages.stdout | from_json | selectattr('name', 'in', wanted_up_to_date_list) | list }}" - name: "Set fact for pip3 out-of-date packages" ansible.builtin.set_fact: pip3_outdated_list: "{{ pip3_outdated_list | default({}) | combine({item.name: item.version}) }}" loop: "{{ pip_outdated_packages.stdout | from_json | selectattr('name', 'in', wanted_out_of_date_list) | list }}" - name: "Verify packages pip, vault-cli, yamllint, docker" ansible.builtin.assert: that: - "'pip' in pip3_updated_list" - "'pip' not in pip3_outdated_list" - "'vault-cli' not in pip3_updated_list" - "'vault-cli' in pip3_outdated_list" - "'yamllint' not in pip3_updated_list" - "'yamllint' in pip3_outdated_list" - "'docker' in pip3_updated_list" - "'docker' not in pip3_outdated_list" - name: "Print up-to-date packages" ansible.builtin.debug: msg: "{{ pip3_updated_list }}" - name: "Print out-of-date packages" ansible.builtin.debug: msg: "{{ pip3_outdated_list }}"