# SonarQube Deployment: "firewalld" Task Fails Due to Missing Python Library

**URL:** <https://forum.ansible.com/t/sonarqube-deployment-firewalld-task-fails-due-to-missing-python-library/11281>\
**Category:** Get Help\
**Tags:** python, devopsdays, playbook, aws\
**Created:** [December 2, 2024, 9:07pm UTC](https://forum.ansible.com/t/sonarqube-deployment-firewalld-task-fails-due-to-missing-python-library/11281 "2024-12-02T21:07:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roman\_Shymoliuk](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/roman_shymoliuk/32/5425_2.png) [@Roman\_Shymoliuk](https://forum.ansible.com/u/Roman_Shymoliuk)\
**Post date:** [December 2, 2024, 9:07pm UTC](https://forum.ansible.com/t/sonarqube-deployment-firewalld-task-fails-due-to-missing-python-library/11281/1 "2024-12-02T21:07:07Z")

</div>

Problem:  
When deploying SonarQube, the task to enable port 9000 fails with the following error:

```auto
fatal: [172. **.*.***]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (firewal) on ip-172. **.*.***.ec2.internal's Python /usr/bin/python3. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter please consult the documentation on ansible_python_interpreter. Version 0.2.11 or newer required (0.3.9 or newer or offline operations)"}

```

What I Have Tried:

1. Installed and reinstalled `firewalld` library on the target system.
2. Ensured `/usr/bin/python3` is being used by specifying `ansible_python_interpreter` in my inventory file.
3. Confirmed the library version is greater than the minimum required (0.2.11) and exceeds the recommended version (0.3.9).
4. Verified the `firewalld` service is installed, running, and included `become` to ensure sufficient permissions.
5. Ensured the playbook grants `sudo` privileges where necessary.

## What am I missing here in my playbook?

- name: Ensure correct Python interpreter is used  
set\_fact:  
ansible\_python\_interpreter: /usr/bin/python3  
become: true

- name: Ensure firewall Python module is installed  
pip:  
name: firewall  
state: present  
become: yes

- name: Install firewalld on Amazon Linux 2  
yum:  
name: firewalld  
state: present  
become: yes

- name: Ensure firewalld is started and enabled  
service:  
name: firewalld  
state: started  
enabled: yes  
become: yes

- name: Install necessary dependencies on Amazon Linux 2  
yum:  
name:  
- wget  
- unzip  
state: present  
when:

- name: Install Java 11 on Amazon Linux 2 using amazon-linux-extras  
command: amazon-linux-extras enable java-openjdk11  
when:

- name: Install Java 11 on Amazon Linux 2  
yum:  
name: java-11-openjdk  
state: present  
when:

- name: Install necessary dependencies on other Linux distributions  
yum:  
name:  
- java-11-openjdk-devel  
- wget  
- unzip  
state: present  
when:

- name: Create sonar user  
user:  
name: sonar  
state: present  
shell: /bin/bash

- name: Create sonar group  
group:  
name: sonar  
state: present

- name: Add sonar user to the sonar group  
user:  
name: sonar  
group: sonar  
state: present

- name: Allow sonar user to have passwordless sudo  
lineinfile:  
dest: /etc/sudoers  
state: present  
line: ‘sonar ALL=(ALL) NOPASSWD: ALL’  
validate: ‘visudo -cf %s’

- name: Download SonarQube tar.gz file  
get\_url:  
url: “[https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.9.0.65466.zip](https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.9.0.65466.zip)”  
dest: /tmp/sonarqube.zip

- name: Unzip SonarQube archive  
unarchive:  
src: /tmp/sonarqube.zip  
dest: /opt/  
remote\_src: yes

- name: Set permissions for SonarQube directory  
file:  
path: /opt/sonarqube-9.9.0.65466  
owner: sonar  
group: sonar  
recurse: yes

- name: Create a systemd service file for SonarQube  
copy:  
dest: /etc/systemd/system/sonarqube.service  
content: |  
[Unit]  
Description=SonarQube service  
After=network.target

- name: Reload systemd to pick up SonarQube service  
systemd:  
daemon\_reload: yes

- name: Start SonarQube service  
service:  
name: sonarqube  
state: started  
enabled: yes

- name: Enable port 9000  
firewalld:  
port: 9000/tcp  
permanent: true  
state: enabled  
become: true

- name: Restart SonarQube service  
service:  
name: sonarqube  
state: restarted

#aws #playbook #python #devopsdays

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [December 2, 2024, 10:35pm UTC](https://forum.ansible.com/t/sonarqube-deployment-firewalld-task-fails-due-to-missing-python-library/11281/2 "2024-12-02T22:35:46Z")

</div>

I believe you need to install the `python3-firewall` package.
