Reputation: 17
I try to get bash tool for db output to ansbisle string,s but doesn't found no any working solution
- set_fact:
db_data: "{{ db.stdout_lines }}"
- debug: var=db_data
Here is debug output
TASK [debug] ***********************************************************************************************************************************************************************
ok: [localhost] => {
"db_data": [
"host: localhost",
"username: user",
"password: pass",
"database: db_name"
]
}
How possible get host, username, password, database as unique strings?
Upvotes: 1
Views: 46
Reputation: 68004
Q: "Get host, username, password, database as unique strings."
A: Instead of a list, create a dictionary. Then simply reference the attributes. For example
- set_fact:
db_data: "{{ db_data|default({})|combine(item|from_yaml) }}"
loop: "{{ db.stdout_lines }}"
- debug:
var: db_data
- debug:
var: db_data.username
give
"db_data": {
"database": "db_name",
"host": "localhost",
"password": "pass",
"username": "user"
}
"db_data.username": "user"
Upvotes: 1
Reputation: 456
- debug:
msg: "{{ item.split(':')[1] }}"
with_items: " {{ db_data }} "
Upvotes: 0