0

I need help fixing regex expression. Its stripping the preceding white spaces after writing to output file. here is the code

  hosts: serv1
  tasks:
    - name: Rename VM hostname
      block:
        - command: hostname -f
          register: result
        - lineinfile:
            path: /home/home/setup.yml
            state: present
            regexp: 'URL: (.*)$'
            line: "URL: 'https://{{ result.stdout }}/key/auth'"

the expected output is

    KEY_USER: ‘KEY_ADMIN'
    KEY_PASS: “KEY_PASS"
    URL: 'https://serv1/key/auth'
    KEY_CLIENT: “CLIENT_KEY"
    LDAP_URL: ‘LDAP_URL'

but I get

    KEY_USER: ‘KEY_ADMIN'
    KEY_PASS: “KEY_PASS"
URL: 'https://serv1/key/auth'
    KEY_CLIENT: “CLIENT_KEY"
    LDAP_URL: ‘LDAP_URL'

Any idea on how to fix it? Thanks

1

The regex is not stripping spaces. You stripped them.

You wrote that the replacement line should not have any leading spaces:

            line: "URL: 'https://{{ result.stdout }}/key/auth'"

If you want leading spaces, you need to put them in. It might look like this:

            line: "    URL: 'https://{{ result.stdout }}/key/auth'"
| improve this answer | |
  • Thanks Michale, It worked. I appreciate your help – jjill007 Oct 16 at 15:17

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.