BTW, your initial problem was that you had
    delegate_to: zabbixprimary
where you needed
    delegate_to: "{{ zabbixprimary }}"
But you're well past that now.

As my old CompSci prof. used to say, "*Don't let these little things 
confuse you. Try to get confused on a higher level.*"
On Tuesday, December 14, 2021 at 9:37:00 PM UTC-5 drum....@gmail.com wrote:

> Hi guys.
>
> I'm trying to use the "delegate_to", to only run a certain task to a group 
> in my inventory.
>
> inventory file:
> [zabbixprimary]
> localhost ansible_port=2235 # zabbix primary
>
> [zabbixslave]
> localhost ansible_port=2236 # zabbix secondary
>
> [zabbix:children]
> zabbixprimary
> zabbixslave
>
> main.yml:
> - name: Setup Zabbix and Grafana
> hosts: zabbix
> become: yes
> become_user: root
> gather_facts: False
>
> task.yml:
> - name: Enable Zabbix HA - primary
> run_once: true
> ansible.builtin.shell: sed -i 's/# HANodeName=/HANodeName={{ 
> hostname_secondary }}/g' /etc/zabbix/zabbix_server.conf && sed -i 's/# 
> NodeAddress=localhost:10051/NodeAddress={{ hostname_primary }}:10051/g' 
> /etc/zabbix/zabbix_server.conf
> when: not ansible_check_mode and zabbix_ha
> delegate_to: zabbixprimary
>
> - name: Enable Zabbix HA - secondary
> run_once: true
> ansible.builtin.shell: sed -i 's/# 
> NodeAddress=localhost:10051/NodeAddress={{ hostname_secondary }}:10051/g' 
> /etc/zabbix/zabbix_server.conf
> when: not ansible_check_mode and zabbix_ha
> delegate_to: zabbixslave
>
> But I get an error:
> fatal: [localhost -> zabbixprimary]: UNREACHABLE! => {"changed": false, 
> "msg": "Failed to connect to the host via ssh: ssh: Could not resolve 
> hostname zabbixprimary: nodename nor servname provided, or not known", 
> "unreachable": true}
>
> Am i doing it right? I couldn't find much information online about how to 
> achieve this.
>
> Thanks!
> Lucas
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fa49dad3-1ce5-491c-80f1-012ac6bd3546n%40googlegroups.com.

Reply via email to