1

I have a follow up question to the thread in here: How do I pass username and password while using Ansible Git module?

I am trying to achieve a similar task where I am passing a username and password to GitHub through Ansible. Here is what I am using for my playbook:

- name: ANSIBLE - Shop Installation
  hosts: host_list
  vars_prompt: 
    - name: "githubuser" 
      prompt: "Enter your github username" 
      private: no 
    - name: "githubpassword" 
      prompt: "Enter your github password" 
      private: yes

- hosts: host_list
  tasks:
  - name: Get the latest version through Git
    git:
    repo: 'https://{{ githubuser }}:{{ githubpassword }}@github.com/foo/bar.git'
    dest: /tmp

After running through this, I get the following error message:

fatal: []: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'githubuser' is undefined\n\nThe error appears to have been in 'playbook.yml'

Any ideas where I may have gone wrong here?

I am running Ansible 2.7.1

TheOrangeRemix
  • 85
  • 3
  • 3
  • 10

2 Answers2

2

I think the structure of your playbook is wrong. Try this:

---
- hosts: host_list
  vars_prompt: 
    - name: "githubuser" 
      prompt: "Enter your github username" 
      private: no 
    - name: "githubpassword" 
      prompt: "Enter your github password" 
      private: yes

  tasks:
  - name: Get the latest version through Git
    git:
      repo: 'https://{{ githubuser }}:{{ githubpassword }}@github.com/foo/bar.git'
      dest: /tmp
JGK
  • 3,710
  • 1
  • 21
  • 26
0

Scope of vars_prompt is a playbook.

Variable githubuser is defined in the first play. Second play knows nothing about it.

Would I have to pass the variable value from the first play to the second? What's the correct way of doing that in this context?

An option would be to configure fact_caching. For example with Redis

[defaults]
fact_caching=redis

In the first play store the variables with set_fact cacheable: yes

In the second play fetch data from Redis

Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63
  • Would I have to pass the variable value from the first play to the second? What's the correct way of doing that in this context? – TheOrangeRemix Nov 11 '18 at 17:42