Hello
I have a variable that contains output from a json file.
`
- name: set fact
set_fact:
test123: “{{ jsonVar | json_query(name_query) }}”
vars:
name_query: “.{name: name, ssh_url_to_repo: ssh_url_to_repo namespace_path: namespace.full_path }”
`
This is the output the command above produces:
`
ok: [host1] => {
“ansible_facts”: {
“test123”: [
{
“name”: “appscomb”,
“namespace_path”: “aws/docker”,
“ssh_url_to_repo”: “ssh://git@gitlab.example.local:4444/aws/docker/appscomb.git”
},
{
“name”: “appscomb”,
“namespace_path”: “software-repositories”,
“ssh_url_to_repo”: “ssh://git@gitlab.example.local:4444/software-repositories/appscomb.git”
},
{
“name”: “java”,
“namespace_path”: “software-repositories”,
“ssh_url_to_repo”: “ssh://git@gitlab.example.local:4444/software-repositories/java.git”
},
{
“name”: “DMI”,
“namespace_path”: “dream-it/docker”,
“ssh_url_to_repo”: “ssh://git@gitlab.example.local:4444/dream-it/docker/dmi.git”
},
{
“name”: “gitlab”,
“namespace_path”: “aws/docker”,
“ssh_url_to_repo”: “ssh://git@gitlab.example.local:4444/aws/docker/gitlab.git”
},
{
“name”: “os-management”,
“namespace_path”: “aws/ansible”,
“ssh_url_to_repo”: “ssh://git@gitlab.example.local:4444/aws/ansible/os-management.git”
},
{
“name”: “appscomb”,
“namespace_path”: “aws/ansible”,
“ssh_url_to_repo”: “ssh://git@gitlab.example.local:4444/aws/ansible/appscomb.git”
},
{
“name”: “xen-management”,
“namespace_path”: “aws/ansible”,
“ssh_url_to_repo”: “ssh://git@gitlab.example.local:4444/aws/ansible/xen-management.git”
},
{
“name”: “aws-docker”,
“namespace_path”: “aws/docker”,
“ssh_url_to_repo”: “ssh://git@gitlab.example.local:4444/aws/docker/aws-docker.git”
},
{
“name”: “dbarchery”,
“namespace_path”: “dream-it/ansible”,
“ssh_url_to_repo”: “ssh://git@gitlab.example.local:4444/dream-it/ansible/dbarchery.git”
},
{
“name”: “dbarchery”,
“namespace_path”: “dream-it/docker”,
“ssh_url_to_repo”: “ssh://git@gitlab.example.local:4444/dream-it/docker/dbarchery.git”
}
]
},
“changed”: false
}
`
How do I access for example, the name or namespace_path or ssh_url_to_repo of any or all of the above?
I have tried this:
`
- name: debug
debug:
msg: “{{ test123.name }}”
with_items: “{{ test123 }}”
`
and this:
`
- name: debug
debug:
msg: “{{ test123[‘name’] }}”
with_items: “{{ test123 }}”
`
But they both seem to be failing with the following error:
`
fatal: [host1]: FAILED! => {
“msg”: “The task includes an option with an undefined variable. The error was: ‘list object’ has no attribute ‘name’\n\nThe error appears to have been in ‘/home/gitlab/roles/gitlab-backup_repos/tasks/main.yml’: line 25, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: debug\n ^ here\n”
`
Many Thanks in Advance!
JS