I created a dictionary of ansible packages filtered from ansible.package_facts, to only contain packages of a specific version. (example shown below)
"filtered_ansible_packages": {
"cool_package1": [
{
"arch": "noarch",
"epoch": "null",
"name": "cool_package1",
"release": "el7",
"version": "1.2.6"
}
],
"cool_package2": [
{
"arch": "noarch",
"epoch": "null",
"name": "cool_package2",
"release": "el7",
"version": "1.4.7"
}
]
}
What I want is to loop through each package and grab the name, release, version and arch.
Then I want to concatenate them into a single string variable we can call "full_package_name", where in the case of cool package 1 would be: "cool_package1.1.2.6.el7.noarch" then store those full package names into a list called "full_package_name_list".
What would be the best way to retrieve the data in the way that I need? should I transform it to a list with "dict2items"? I am new to Ansible so any help would be really appreciated.
2
Answers
Q: "Loop through each package and grab the name, release, version, and arch."
A: Convert the dictionary to a list and iterate subelements
gives
Q: "Store full package names into a list full_package_name_list"
A: Use json_query to select the attributes and join them
gives
Example of a complete playbook for testing
Q: "What I want is to
loop
through each package and grab thename
,release
,version
andarch
. Then I want to concatenate them into a single string variable we can callfull_package_name
…"A minimal example playbook
will provide such behavior.
One could even filter the package dictionary for certain properties like the
release
before.