#Ansible is not able to work with "dnf module" outside of installing them. #Shell has to be used to check if a specific app stream is enabled, and then disable and enable #the appropriate app streams to get the correct nodejs version for Yarn. - name: Check if NodeJS 10 module is enabled become: true shell: "dnf module list nodejs | grep -q 'nodejs 10 \\[d\\]\\[e\\]' && echo true || echo false" register: is_node10_enabled ignore_errors: true when: - ansible_os_family == "RedHat" - ansible_facts['distribution_major_version'] == "8" - name: Disable NodeJS 10 module become: true shell: "dnf module disable nodejs:10 -y" ignore_errors: true when: - ansible_os_family == "RedHat" - ansible_facts['distribution_major_version'] == "8" - is_node10_enabled.stdout | bool - name: Enable NodeJS 16 module become: true shell: "dnf module enable nodejs:16 -y" ignore_errors: true when: - ansible_os_family == "RedHat" - ansible_facts['distribution_major_version'] == "8" - is_node10_enabled.stdout | bool - name: Install NodeJS 16 via DNF become: true dnf: name: "@nodejs:16" state: present when: - ansible_os_family == "RedHat" - ansible_facts['distribution_major_version'] == "8" #RHEL9 already installs NodeJS 16 by default - name: Install NodeJS via DNF become: true dnf: name: "nodejs" state: present when: - ansible_os_family == "RedHat" - ansible_facts['distribution_major_version'] == "9"