ansible error 'first argument must be string or compiled pattern'
The task which fails is this one:

 - name: replace hostname in config
   replace:
     path: /opt/agentd.conf
     regexp: #\s+Hostname\=
     replace: Hostname={{hname}}
     backup: yes


Try like this:

 - name: replace hostname in config
   replace:
     path: /opt/agentd.conf
     regexp: '#\s+Hostname\=.*$'
     replace: Hostname={{hname}}
     backup: yes


Note that if you don't add .*$, the task will only replace # Hostname= and you will end up with a Hostname=oldhostnamenewhostname.