# ansible error 'first argument must be string or compiled pattern'

**URL:** <https://forum.ansible.com/t/ansible-error-first-argument-must-be-string-or-compiled-pattern/31132>\
**Category:** Ansible Project\
**Created:** [August 27, 2019, 8:08am UTC](https://forum.ansible.com/t/ansible-error-first-argument-must-be-string-or-compiled-pattern/31132 "2019-08-27T08:08:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fae\_Az](https://avatars.discourse-cdn.com/v4/letter/f/f07891/32.png) [@Fae\_Az](https://forum.ansible.com/u/Fae_Az)\
**Post date:** [August 27, 2019, 8:08am UTC](https://forum.ansible.com/t/ansible-error-first-argument-must-be-string-or-compiled-pattern/31132/1 "2019-08-27T08:08:39Z")

</div>

I have this code in my playbook:

```auto
- hosts: standby
  remote_user: root
  tasks:
  - name: replace hostname in config
    replace:
      path: /opt/agentd.conf
      regexp: #\s+Hostname\=
      replace: Hostname={{hname}}
      backup: yes
  - name: add database array in files
    lineinfile:
      path: /opt/zabbix_agent/share/scripts/{{ item }}
      line: 'DBNAME_ARRAY=( {{dbname}} )'
      insertafter: DB2PATH=/home/db2inst1/sqllib/bin/db2
      backup: yes
  with_items:
   - Connections
   - HadrAndLog
   - Memory
   - Regular
 - name: restart service
   shell: /etc/init.d/agent restart
   register: command_output
   become: yes
   become_user: root
   tags: restart
 - debug: msg="{{command_output.stdout_lines}}"
 tags: set_config_st

```

it will replace `# Hostname=` in a config file with `Hostname= givenhostname` and add an array in 4 scripts. array is the name of given database. then it will restart the agent to apply the changes.  
when i run this command:

```auto
ansible-playbook -i /Ansible/inventory/hostfile /Ansible/provision/nconf.yml --tags set_config_st --extra-vars "hname=fazi dbname=fazidb"

```

i get this error:

`first argument must be string or compiled pattern`  
i searched a bit but couldn’t find the reason. what should i do?

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [August 27, 2019, 8:37am UTC](https://forum.ansible.com/t/ansible-error-first-argument-must-be-string-or-compiled-pattern/31132/2 "2019-08-27T08:37:19Z")

</div>

> I have this code in my playbook:
> 
> \>- hosts: standby remote\_user: root tasks: - name: replace hostname in config replace: path: /opt/agentd.conf regexp:  
> #\s+Hostname\= replace: Hostname={{hname}} backup: yes - name: add database array in files lineinfile: path:  
> /opt/zabbix\_agent/share/scripts/{{ item }} line: 'DBNAME\_ARRAY=( {{dbname}} )' insertafter:  
> DB2PATH=/home/db2inst1/sqllib/bin/db2 backup: yes with\_items: - Connections - HadrAndLog - Memory - Regular - name:  
> restart service shell: /etc/init.d/agent restart register: command\_output become: yes become\_user: root tags: restart -  
> debug: msg="{{command\_output.stdout\_lines}}" tags: set\_config\_st |
> 
> it will replace |# Hostname=| in a config file with |Hostname= givenhostname| and add an array in 4 scripts. array is  
> the name of given database. then it will restart the agent to apply the changes.  
> when i run this command:
> 
> \>ansible-playbook -i /Ansible/inventory/hostfile /Ansible/provision/nconf.yml --tags set\_config\_st --extra-vars  
> "hname=fazi dbname=fazidb" |
> 
> i get this error:
> 
> \>first argument must be string or compiled pattern|  
> i searched a bit but couldn't find the reason. what should i do?

1. consider to use the Zabbix agent role from Galaxy ([https://galaxy.ansible.com/dj-wasabi/zabbix-agent](https://galaxy.ansible.com/dj-wasabi/zabbix-agent))  
2. show the complete error, it may include the line number

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Fae\_Az](https://avatars.discourse-cdn.com/v4/letter/f/f07891/32.png) [@Fae\_Az](https://forum.ansible.com/u/Fae_Az)\
**Post date:** [August 28, 2019, 2:25am UTC](https://forum.ansible.com/t/ansible-error-first-argument-must-be-string-or-compiled-pattern/31132/3 "2019-08-28T02:25:40Z")

</div>

found the solution. i should use ‘#\s+Hostname=’ in quotes
