Use xml_module instead of blockinfile and lineinfile
It seems to be a better idea to use https://docs.ansible.com/ansible/latest/collections/community/general/xml_module.html to modify the xml files in a more "verbose" way
It seems to be a better idea to use https://docs.ansible.com/ansible/latest/collections/community/general/xml_module.html to modify the xml files in a more "verbose" way