Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix zabbix_agent role on Windows #1290

Merged
merged 1 commit into from
Jul 4, 2024

Conversation

emrocha
Copy link
Contributor

@emrocha emrocha commented Jun 12, 2024

SUMMARY

Role zabbix_agent is not working on Windows.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

Role zabbix_agent

ADDITIONAL INFORMATION
  • Single quotes to avoid double backslashes.
  • Remove default variable zabbix_agent_win_include because zabbix-agent2 may be used.
  • Fix agent config template name to agent.conf.j2
  • Default values for zabbix_win_package and zabbix_win_download_link
  • Default value for zabbix_agent_controlsocket
  • zabbix_agent_tlspskidentity_check and zabbix_agent_tlspskcheck must be defined in a separately task. There were two tasks that could define these variables. If the second task is skipped, as it has register keyword, the variable is reset.
  • Define a value for _win_include

Copy link
Collaborator

@pyrodie18 pyrodie18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution. A few comments but looks good.

@@ -3,17 +3,21 @@
- name: AutoPSK | Check for existing TLS PSK identity | Windows
ansible.windows.win_stat:
path: "{{ zabbix_agent_tlspskidentity_file }}"
register: zabbix_agent_tlspskidentity_check
register: zabbix_agent_tlspskidentity_check_windows
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how zabbix_agent_tlspskidentity_check could be set twice since the two choices for the ansible_os_family variable are mutually exclusive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original code, there is two tasks that use the "register" keyword for the same variable. This two task are, indeed, mutual exclusive. But Ansible also set the variable if the task is skipped.

If a task fails or is skipped, Ansible still registers a variable with a failure or skipped status, unless the task is skipped based on tags.
https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html

@@ -12,17 +12,21 @@
- name: AutoPSK | Check for existing TLS PSK file | Windows
ansible.windows.win_stat:
path: "{{ zabbix_agent_tlspskfile }}"
register: zabbix_agent_tlspskcheck
register: zabbix_agent_tlspskcheck_windows
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how zabbix_agent_tlspskcheck could be set twice since the two choices for the ansible_os_family variable are mutually exclusive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original code, there is two tasks that use the "register" keyword for the same variable. This two task are, indeed, mutual exclusive. But Ansible also set the variable if the task is skipped.

If a task fails or is skipped, Ansible still registers a variable with a failure or skipped status, unless the task is skipped based on tags.

https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html

@@ -3,7 +3,8 @@ _logfile: /var/log/zabbix/zabbix_agent2.log
_include: /etc/zabbix/zabbix_agent2.d
_tls_subject: "{{ zabbix_agent_tlsservercertsubject | default(omit) }}" # FIXME this is not correct and should be removed with 2.0.0, here only to prevent regression
_win_package: zabbix_agent2-{{ zabbix_version_long }}-windows-amd64-openssl-static.zip
_win_download_link: "{{ zabbix_win_download_url }}/{{ zabbix_version_long | regex_search('^\\d+\\.\\d+') }}/{{ zabbix_version_long }}/{{ zabbix2_win_package }}"
_win_logfile: "{{ zabbix_win_install_dir }}\\zabbix_agent2.log"
_win_download_link: "{{ zabbix_win_download_url }}/{{ zabbix_version_long | regex_search('^\\d+\\.\\d+') }}/{{ zabbix_version_long }}/{{ zabbix2_win_package | default('_win_package') }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the latest changes. Support for zabbix2_win_package has been removed with the release of 3.0.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you suggest as an alternative?

The code below uses the variable _win_download_link when the variables zabbix_agent_win_download_link and zabbix_agent2_win_download_link are not set.

---
- name: "Windows | Set some variables"
ansible.builtin.set_fact:
zabbix_agent_win_download_link: "{{ zabbix_agent_win_download_link is defined | ternary(zabbix_agent_win_download_link, zabbix_agent2_win_download_link) | default(_win_download_link) }}"

On the other hand, the code below uses the variable zabbix2_win_package that is not set by default.

_win_download_link: "{{ zabbix_win_download_url }}/{{ zabbix_version_long | regex_search('^\\d+\\.\\d+') }}/{{ zabbix_version_long }}/{{ zabbix2_win_package }}"

Therefore, the script will fail if none of these variables are set when the Role is applied.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I misunderstood your comment. Do you just want to unify the parameter for Zabbix_agent and Zabbix_agent2?


- name: "Set Include Path Info"
ansible.builtin.set_fact:
zabbix_agent_include: "{{ zabbix_agent_win_include is defined | ternary(zabbix_agent_win_include, zabbix_agent2_win_include) | default(_win_include) }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the latest changes. Support for zabbix_agent2_win_include has been removed with the release of 3.0.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In template of zabbix_agent.conf, the parameter Include= will be set because the variable zabbix_agent_include is defined in the main.yml script.

- name: Set Variables
ansible.builtin.set_fact:
zabbix_agent_include: "{{ zabbix_agent_include is defined | ternary(zabbix_agent_include, _include) }}"

{{ (zabbix_agent_include is defined and zabbix_agent_include is not none) | ternary('', '# ') }}Include={{ zabbix_agent_include | default('') }}

So, for Windows, if the variable zabbix_agent_include was not explicited defined, the parameter Include will be set to /etc/zabbix/zabbix_agentd.d because of the code below.

_include: /etc/zabbix/zabbix_agentd.d

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I misunderstood your comment. Do you just want to unify the parameter for Zabbix_agent and Zabbix_agent2?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! There are no more zabbix_agent2 vars. They are all combined into zabbix_agent vars

@@ -191,8 +192,8 @@

- name: "Windows | Set installation settings (agent 2)"
ansible.builtin.set_fact:
zabbix_win_package: "{{ zabbix2_win_package }}"
zabbix_win_download_link: "{{ zabbix2_win_download_link }}"
zabbix_win_package: "{{ zabbix2_win_package | default('_win_package') }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the latest changes. Support for zabbix2_win_package has been removed with the release of 3.0.0

zabbix_win_package: "{{ zabbix2_win_package }}"
zabbix_win_download_link: "{{ zabbix2_win_download_link }}"
zabbix_win_package: "{{ zabbix2_win_package | default('_win_package') }}"
zabbix_win_download_link: "{{ zabbix2_win_download_link | default('_win_download_link') }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the latest changes. Support for zabbix2_win_download_link has been removed with the release of 3.0.0

@david-sieg
Copy link
Contributor

Are there any news here?

@the-iot
Copy link

the-iot commented Jun 27, 2024

the agent role is fixed by commit b0f05b4 but the version 3.0.1 is not released.

see #1301 (comment)

@emrocha
Copy link
Contributor Author

emrocha commented Jun 28, 2024

I was a little busy this week, but I will take a look soo n.

@emrocha
Copy link
Contributor Author

emrocha commented Jul 1, 2024

the agent role is fixed by commit b0f05b4 but the version 3.0.1 is not released.

see #1301 (comment)

The code below in zabbix_agent role still include the role zabbix_repo for Windows hosts.

- name: Install Repository
ansible.builtin.include_role:
name: community.zabbix.zabbix_repo
vars:
zabbix_repo_version: "{{ zabbix_agent_version }}"
zabbix_repo_package: "{{ zabbix_agent_package }}"
zabbix_repo_apt_priority: "{{ zabbix_agent_apt_priority | default (omit) }}"
when:
- zabbix_manage_repo | default(true)
- not (zabbix_agent_docker | bool) or ansible_os_family == "Windows"

In my view, the correct logic in the "when" statement shoud be:

 when:
    - zabbix_manage_repo | default(true)
    - not (zabbix_agent_docker | bool)
    - ansible_os_family != "Windows"

In the role zabbix_repo, the code below tries to load the Windows.yml file that do not exists in role zabbix_repo.

- name: Install the correct repository
ansible.builtin.include_tasks: "{{ ansible_os_family }}.yml"

For this reason, the script still does not work for Windows Hosts.

@david-sieg
Copy link
Contributor

Yes mate, you're right. Can u open a PR?

@emrocha
Copy link
Contributor Author

emrocha commented Jul 1, 2024

@david-sieg
I made the correction in the "when" statement for the "Install Repository" task now.
But a keep it in this pull request that include others changes. Is the ok for you?

@pyrodie18

I remove some "zabbix2_*" variables. But not all. The code below is necessary because the script tries to remove old versions and need to test both zabbix agents (1 and 2).

- name: "Windows | Set variables specific to Zabbix"
ansible.builtin.set_fact:
zabbix_win_svc_name: Zabbix Agent
zabbix_win_exe_path: '{{ zabbix_win_install_dir }}\bin\zabbix_agentd.exe'
zabbix_win_config_name: "zabbix_agentd.conf"
zabbix2_win_svc_name: Zabbix Agent 2
zabbix2_win_exe_path: '{{ zabbix_win_install_dir }}\bin\zabbix_agent2.exe'
zabbix2_win_config_name: "zabbix_agent2.conf"

@david-sieg
Copy link
Contributor

That‘s ok for me, thx!

@the-iot
Copy link

the-iot commented Jul 2, 2024

please add merge into main and release 3.0.2 - momentary we cant install zabbix agent on windows with release 3.x

@pyrodie18
Copy link
Collaborator

OK, this looks good to me. The only thing still needed is change fragment(s).

@emrocha
Copy link
Contributor Author

emrocha commented Jul 3, 2024

OK, this looks good to me. The only thing still needed is change fragment(s).

I didn't understand. What do you mean by "fragments"?

Do I need to change anything else?

@BGmot
Copy link
Collaborator

BGmot commented Jul 4, 2024

OK, this looks good to me. The only thing still needed is change fragment(s).

I didn't understand. What do you mean by "fragments"?

Do I need to change anything else?

You need to create a file describing your changes here https://github.com/ansible-collections/community.zabbix/tree/main/changelogs/fragments

Here you can read instructions about how to create changelog fragments https://docs.ansible.com/ansible/latest/community/development_process.html#creating-a-changelog-fragment

@pyrodie18 pyrodie18 merged commit d756b78 into ansible-collections:main Jul 4, 2024
102 checks passed
@the-iot
Copy link

the-iot commented Jul 4, 2024

ok...merge is done.

please add tag for the new version 3.0.2 and publish to galaxy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants