'Ansible parse file and read into variables
I have a file I have to read from, that is written like this: (it cannot be changed)
user_passwords:
- { username: user1, plaintextPassword: password }
- { username: user2, plaintextPassword: password }
I need to read the file, then assign the values above to the following variables and write them to a file.
I'm not sure how to loop through this in ansible.
Variables and values I need to write: user1: user1 user1password: password user2: user2 user2password: password
Here is what I've tried:
- name: Read file
include_vars:
file: myfile
- name: assign variables
user1: {{ username.1 }}
user1password {{ plaintextPassword.1 }}
user2: {{ username.2 }}
user2password: {{ plaintextPassword.2 }}
loop: user_passwords
but this is not giving me any results. Does anyone have any ideas?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
