votes up 2

Invalid variable name in 'register' specified: '%s'

Package:
ansible
github stars 49704
Exception Class:
AnsibleError

Raise code

            # preserve no log
            result["_ansible_no_log"] = self._play_context.no_log

            # update the local copy of vars with the registered value, if specified,
            # or any facts which may have been generated by the module execution
            if self._task.register:
                if not isidentifier(self._task.register):
                    raise AnsibleError("Invalid variable name in 'register' specified: '%s'" % self._task.register)

                vars_copy[self._task.register] = result = wrap_var(result)

            if self._task.async_val > 0:
                if self._task.poll > 0 and not result.get('skipped') and not result.get('failed'):
                    result = self._poll_async_result(result=result, templar=templar, task_vars=vars_copy)

Ways to fix

votes up 2 votes down

This code will throw you the same exception

---
  - name: "Playing with Ansible and Git"
    hosts: localhost
    connection: local
    tasks:

    - name: "just execute a ls -lrt command"
      shell: "ls -la"
      register: "1output"

    - debug: var=1output.stdout_lines

The problem is that a valid variable to register should contain only letters, numbers and '_'. But it shouldn't start with a number neither it should contain any spaces

---
  - name: "Playing with Ansible and Git"
    hosts: localhost
    connection: local
    tasks:

    - name: "just execute a ls -lrt command"
      shell: "ls -la"
      register: "output2"

    - debug: var=output2.stdout_lines

This code is valid.

Jun 25, 2021 georgiev.georgi1999 answer

Add a possible fix

Please authorize to post fix