kwoodson / ansible-role-yedit

Ansible Role for Yaml editing
164 stars 62 forks source link

issues with dots in keys #90

Closed olifur closed 2 years ago

olifur commented 3 years ago

Hi kwoodson,

I have the following problem when my keys contain dots such as in domain names

My target yaml structure I want to write:

lab00001:
  hosts:
    mydomainname.example.com
       horst

Now using quotes I try to escape the dots in the domain name

- hosts: localhost
  gather_facts: no
  roles:
  - kwoodson.yedit
  tasks:
  - name: insert simple key, value
    yedit:
      src: /tmp/xxx.yaml
      key: 
        lab00001
          hosts
            "mydomainname.example.com"
      value: horst
      state: present

this does not write anything into the file.

Other combinations of escaping dots in yaml do not work either for me, e.g

            "mydomainname\.example\.com"

If I leave the dots and quotes, it writes content to the file

- hosts: localhost
  gather_facts: no
  roles:
  - kwoodson.yedit
  tasks:
  - name: insert simple key, value
    yedit:
      src: /tmp/xxx.yaml
      key: 
        lab01
          hosts
            mydomainnameXXX
      value: horst
      state: present

Is there a way to use dots in keys (escape) with your module?

Thanks in advance, Oliver

olifur commented 2 years ago

After reviewing the source code I found the solution myself

 - name: insert simple key, value
    yedit:
      src: /tmp/xxx.yaml
      key: 
        lab01.hosts
      value: 
        horst:
          'mydomainname.abc.it.de'

I close the issue for now.