diff --git a/zabbix-agent/templates/zabbix_agentd.conf.j2 b/zabbix-agent/templates/zabbix_agentd.conf.j2
index ae3829d68978f32eaf97f718db195c9fe746047e..e0e92e1b5cca1d77b843998ec266b900494bae80 100644
--- a/zabbix-agent/templates/zabbix_agentd.conf.j2
+++ b/zabbix-agent/templates/zabbix_agentd.conf.j2
@@ -70,7 +70,12 @@ LogFileSize=0
 #
 # Mandatory: no
 # Default:
+
+{% if zabbix_version is version("5.0", ">=") %}
+AllowKey=system.run[*]
+{% else %}
 EnableRemoteCommands=1
+{% endif %}
 
 ### Option: LogRemoteCommands
 #	Enable logging of executed shell commands as warnings.
@@ -262,7 +267,7 @@ Hostname={{ ansible_fqdn }}
 # Default:
 # Include=
 
-{% if ansible_distribution_major_version is version("10", ">=") %}
+{% if not zabbix_external_repo %}
 Include=/etc/zabbix/zabbix_agentd.conf.d/*.conf
 {% else %}
 Include=/etc/zabbix/zabbix_agentd.d/*.conf