I found a solution here: 
https://www.dasblinkenlichten.com/ansible-roles-and-variables/

   "In the role definition Variables can also be defined as part of a role. 
There are two places this can be done with variables defined in either the 
‘vars’ or the ‘default’ directory of the role.  Much in the same way we defined 
other role functions, we can also define a ‘main.yml’ file in both of these 
directories that define variable to use as part of the role.  For instance 
let’s assume that we have the following defined as 
‘/etc/ansible/roles/webserver/defaults/main.yml’ "

/project
  |___ /roles
       |__ /role1
           |__ /defaults
               |__ main.yml

---
webserver_package: tomcat
http_server_port: 80



sorry, maybe I should have searched for this first




> On 11/04/2021 6:06 AM dulhaver via Ansible Project 
> <ansible-project@googlegroups.com> wrote:
> 
> 
> I have a couple of standalone playbooks which I am trying to transform to 
> role-based execition.
> 
> At the start I get the hostname in a user dialog 
> https://pastebin.com/qR1zG9BR , then go in with the first play when ther is 
> no ssh available on target yet to set up authorized_keys file, so I go in for 
> the first play with user/pw combination which I want to pass as variables.
> 
> - hosts: target_host_group
>   vars_files: defaults.yml
>   vars:
>     ansible_ssh_pass: superawesomepwd
>     ansible_user: user
> 
> I am aware that I need to make sure this is safe (probably using vault) yet, 
> but that is not the point of my question here.
> 
> What I need to figure out is how to pass the paragraph above in the main.yaml 
> of my initial role (and only that role, not the other ones).
> using the syntax above or just
> 
> ---
> vars_files: defaults.yml
> vars:
>   ansible_ssh_pass: superawesomepwd
>   ansible_user: user
> 
> - name: here comes the first asctual TASK
> ...
> ...
> 
> does not work.
> 
> 
> --
> 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-project+unsubscr...@googlegroups.com 
> mailto:ansible-project+unsubscr...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/1493512520.2560.1636002362368%40office.mailbox.org
>  
> https://groups.google.com/d/msgid/ansible-project/1493512520.2560.1636002362368%40office.mailbox.org?utm_medium=email&utm_source=footer
>  .
> 

-- 
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-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1931014798.15771.1636016055141%40office.mailbox.org.

Reply via email to