1

I am trying to use Ansible to replace a sample text with a variable. I have tried using no quotes, "", and '', but nothing seems to work. I also tried using the replace module and the lineinfile module.

Please let me know what I am doing wrong.

- hosts: 10.1.1.10
  become: yes

  vars:
    server1:
      1a: "ED:5A:13:AA:34:20"
      2a: "ED:5A:13:AA:34:21"

  tasks:
  - name: Replace mac address in file  
    lineinfile:
      path: /tmp/file.json.j2
      regexp: 'FILL_THIS_IN'
      line: "{{ server1.1a }}"
4

Excerpt from the documentation about variables:

Variable names should be letters, numbers, and underscores. Variables should always start with a letter.

So you should refactor to:

server1:
  a1: "ED:5A:13:AA:34:20"
  a2: "ED:5A:13:AA:34:21"

and in the code:

line: "{{ server1.a1 }}"
  • Konstantin Suvorov, I appreciate your help in finding my mistake. I had read that about variables, but I guess I overlooked that. Thank you also for formating my code correctly. – dev_oper Aug 9 '17 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.