variable undefined?

55 views
Skip to first unread message

Dave York

unread,
Feb 29, 2020, 3:48:45 AM2/29/20
to Ansible Project
I'm confused why I'm getting a 'variable undefined' error with this playbook, anyone have any idea?

hostslocalhost
  connectionlocal
  gather_factsyes

  tasks:
  - nameGenerate a temporary random password for template/os customization
    set_fact
      randopass"{{ lookup('password', '/dev/null length=24 chars=ascii_letters') }}"
  
... I use '{{ randopass }}' somewhere else in this play and its fine... but then I get to this part:

hostsstaging
  vars:
      ansible_userAdministrator
      ansible_password'{{ randopass }}'
  gather_factsyes

ERROR:
The field 'password' has an invalid value, which includes an undefined variable. The error was: 'randopass' is undefined

Jean-Yves LENHOF

unread,
Feb 29, 2020, 3:56:04 AM2/29/20
to ansible...@googlegroups.com

Hi,

Variable are for a host.... You use "localhost" and "staging"

unless the group staging contains only localhost, yes you will have some undefined variable for the different hosts in your staging group

Regards,

JYL

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1a0e91d7-88fe-4d3f-96b4-115de45f29f6%40googlegroups.com.

Vladimir Botka

unread,
Feb 29, 2020, 4:28:38 AM2/29/20
to Dave York, ansible...@googlegroups.com
On Sat, 29 Feb 2020 00:48:45 -0800 (PST)
Dave York <dave...@gmail.com> wrote:

> - hosts: localhost
> connection: local
> gather_facts: yes
>
> tasks:
> - name: Generate a temporary random password for template/os customization
> set_fact:
> randopass:
> "{{ lookup('password', '/dev/null length=24 chars=ascii_letters') }}"

Instead of "hosts: localhost" run the play with "hosts: staging" and limit
the fork to "run_once: true". For example

- hosts: staging
tasks:
- name: Generate a temporary random password for template/os customization
set_fact:
randopass: ...
run_once: true

This way the variable "randopass" will be defined in the "hostvars" of all
hosts in the group staging.

HTH,

-vlado
Reply all
Reply to author
Forward
0 new messages