I see the attachment is missing for the playbook section hence pasting it 
here again..

---
- name: Playbook to replace line in zabbix_agentd.conf
  hosts: all
  #remote_user: root
  gather_facts: False

  tasks:
  - name: Changing the zabbix-agent configuration on the client
    lineinfile:
      path: /tmp/zabbix_agentd.conf
      ### line to be searched & matched
      regexp: '{{ item.From }}'
      ### new line to be replaced with the old matched one
      line: '{{ item.To }}'
      state: present
      backup: yes
      backrefs: yes

    with_items:
    - { From: '#ServerActive=myzabbix1.example.com', To: 
'ServerActive=myzabbix2.example.com'}
    - { From: 
'Server=192.168.1.1,192.168.1.2,192.168.1.3,192.168.1.4,192.168.1.5', To: 
'Server=192.168.1.1,192.168.1.2,192.168.1.3,192.168.1.10,192.168.1.5'}
    # Actions will be triggered at the end of each block of task and 
notifies a handler.
    notify: restart_zabbix_service

  handlers:
  - name: restart_zabbix_service
    # referenced by a globally unique name and are notified by notifiers.
    service:
      name: zabbix-agentd
      state: restarted

On Friday, July 10, 2020 at 7:45:56 PM UTC+5:30 Karn Gusain wrote:

> I have an Ansible playbook where I need to change the Server Name in one 
> line and an Specific IP address in another line, as in this line there are 
> a bunch of IP address separated by a comma.
>
> I have the below play which works absolutely fine in case I have to change 
> the entire IP address line with the defined set of IP addresses, But I'm 
> looking for specific IP address i.e. 191.168.1.4 to be looked upon and if 
> found then just replace that only and leave the rest of the IP as it is.
>
> Below is the Playbook..
>
>
> In case below section not visible in above..
>
> with_items:
>       - { From: '#ServerActive=myzabbix1.example.com', To: 'ServerActive=
> myzabbix2.example.com'}
>
>        - { From: 
> 'Server=192.168.1.1,192.168.1.2,192.168.1.3,192.168.1.4,192.168.1.5', To: 
> 'Server=192.168.1.1,192.168.1.2,192.168.1.3,192.168.1.10,192.168.1.5'} 
>
>
>

-- 
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/378fad87-f0ed-4649-8b6c-348ca2ba77c6n%40googlegroups.com.

Reply via email to