#ansible (2021-10)


Discussions related to ansible configuration management


Ozzy Aluyi avatar
Ozzy Aluyi

Hi All, I am trying to comment out a line in an SNMP conf. file using ansible. The line has some whitespaces. How can I use ansible to comment out this line. I have tried using the replace command, no joy!

Ozzy Aluyi avatar
Ozzy Aluyi
- name: Comment out agent address.
      path: /etc/snmp/snmpd.conf
      regexp: '^(.*agentaddress,[::1].*)'
      replace: '#agentaddress,[::1]'
Zoltan K avatar
Zoltan K

hi, in your regexp you can refer your bracketed matched pattern as \1 see here as  well https://www.mydailytutorials.com/uncommentcomment-lines-files-using-ansible/ also your pattern looks to be faulty check examples in docs here//docs.ansible.com/ansible/latest/collections/ansible/builtin/replace_module.html> I would replace spaces with \s+ also if this is a full line match I would add $ at the end… cheers.

Ozzy Aluyi avatar
Ozzy Aluyi

Great thanks @Zoltan K . That worked