https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html#with-items

with_items is replaced by "loop" and simply iterates over a list. In the task 
you can reference any of the dictionary elements of the specific list entry.

debug:
  msg: "{{ item.name }} - {{ item.disabled }} - {{ item.has_wiki }}"
loop: "{{ json }}"


Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Feb 5, 2024, at 12:26 PM, John Simmons <[email protected]> wrote:

Hi Hope you can help me,

I have a step in a playbook that makes a uri call to the gihub api servers and 
returns all the info regarding all of our repo's. I need to create a with_items 
list with information from that json response to have 3 items per repo(for 
example) for the next part of the playbook. Does anybody know any great ideas 
on how to go about this?

wanted with_items list:
with_items: - { name: REPO1, disabled: False, has_wiki: True } - { name: REPO2, 
disabled: False, has_wiki: True }

Example json output from previous step:

"json": [
    {
    "allow_forking": true,
    "archive_url": 
"https://api.github.com/repos/**********/REPO1/{archive_format}{/ref}";,
    "archived": false,
    "assignees_url": 
"https://api.github.com/repos/**********/REPO1/assignees{/user}";,
    "blobs_url": 
"https://api.github.com/repos/**********/REPO1/git/blobs{/sha}";,
    "branches_url": 
"https://api.github.com/repos/**********/REPO1/branches{/branch}";,
    "clone_url": "https://github.com/**********/REPO1.git";,
    "collaborators_url": 
"https://api.github.com/repos/**********/REPO1/collaborators{/collaborator}";,
    "comments_url": 
"https://api.github.com/repos/**********/REPO1/comments{/number}";,
    "commits_url": 
"https://api.github.com/repos/**********/REPO1/commits{/sha}";,
    "compare_url": 
"https://api.github.com/repos/**********/REPO1/compare/{base}...{head}";,
    "contents_url": 
"https://api.github.com/repos/**********/REPO1/contents/{+path}";,
    "contributors_url": 
"https://api.github.com/repos/**********/REPO1/contributors";,
    "created_at": "2023-12-14T09:22:56Z",
    "default_branch": "main",
    "deployments_url": 
"https://api.github.com/repos/**********/REPO1/deployments";,
    "description": "********************",
    "disabled": false,
    "downloads_url": "https://api.github.com/repos/**********/REPO1/downloads";,
    "events_url": "https://api.github.com/repos/**********/REPO1/events";,
    "fork": true,
    "forks": 0,
    "forks_count": 0,
    "forks_url": "https://api.github.com/repos/**********/REPO1/forks";,
    "full_name": "**********/REPO1",
    "git_commits_url": 
"https://api.github.com/repos/**********/REPO1/git/commits{/sha}";,
    "git_refs_url": 
"https://api.github.com/repos/**********/REPO1/git/refs{/sha}";,
    "git_tags_url": 
"https://api.github.com/repos/**********/REPO1/git/tags{/sha}";,
    "git_url": "git://github.com/**********/REPO1.git",
    "has_downloads": true,
    "has_issues": true,
    "has_pages": false,
    "has_projects": true,
    "has_wiki": true,
    "homepage": null,
    "hooks_url": "https://api.github.com/repos/**********/REPO1/hooks";,
    "html_url": "https://github.com/**********/REPO1";,
    "id": ***********,
    "issue_comment_url": 
"https://api.github.com/repos/**********/REPO1/issues/comments{/number}";,
    "issue_events_url": 
"https://api.github.com/repos/**********/REPO1/issues/events{/number}";,
    "issues_url": 
"https://api.github.com/repos/**********/REPO1/issues{/number}";,
    "keys_url": "https://api.github.com/repos/**********/REPO1/keys{/key_id}";,
    "labels_url": "https://api.github.com/repos/**********/REPO1/labels{/name}";,
    "language": "Python",
    "languages_url": "https://api.github.com/repos/**********/REPO1/languages";,
    "license": null,
    "merges_url": "https://api.github.com/repos/**********/REPO1/merges";,
    "milestones_url": 
"https://api.github.com/repos/**********/REPO1/milestones{/number}";,
    "mirror_url": null,
    "name": "REPO1",
    "node_id": "***********",
    "notifications_url": 
"https://api.github.com/repos/**********/REPO1/notifications{?since,all,participating}";,
    "open_issues": 0,
    "open_issues_count": 0,
    "owner": {
        "avatar_url": "https://avatars.githubusercontent.com/u/200000?v=4";,
        "events_url": 
"https://api.github.com/users/**********/events{/privacy}";,
        "followers_url": "https://api.github.com/users/**********/followers";,
        "following_url": 
"https://api.github.com/users/**********/following{/other_user}";,
        "gists_url": "https://api.github.com/users/**********/gists{/gist_id}";,
        "gravatar_id": "",
        "html_url": "https://github.com/**********";,
        "id": 200000,
        "login": "**********",
        "node_id": "********",
        "organizations_url": "https://api.github.com/users/**********/orgs";,
        "received_events_url": 
"https://api.github.com/users/**********/received_events";,
        "repos_url": "https://api.github.com/users/**********/repos";,
        "site_admin": false,
        "starred_url": 
"https://api.github.com/users/**********/starred{/owner}{/repo}";,
        "subscriptions_url": 
"https://api.github.com/users/**********/subscriptions";,
        "type": "Organization",
        "url": "https://api.github.com/users/**********";
    },
    "permissions": {
        "admin": false,
        "maintain": false,
        "pull": true,
        "push": false,
        "triage": false
    },
    "private": true,
    "pulls_url": "https://api.github.com/repos/**********/REPO1/pulls{/number}";,
    "pushed_at": "2024-01-09T10:02:27Z",
    "releases_url": 
"https://api.github.com/repos/**********/REPO1/releases{/id}";,
    "role_name": "read",
    "size": 1030,
    "ssh_url": "[email protected]:**********/REPO1.git",
    "stargazers_count": 0,
    "stargazers_url": 
"https://api.github.com/repos/**********/REPO1/stargazers";,
    "statuses_url": 
"https://api.github.com/repos/**********/REPO1/statuses/{sha}";,
    "subscribers_url": 
"https://api.github.com/repos/**********/REPO1/subscribers";,
    "subscription_url": 
"https://api.github.com/repos/**********/REPO1/subscription";,
    "svn_url": "https://github.com/**********/REPO1";,
    "tags_url": "https://api.github.com/repos/**********/REPO1/tags";,
    "teams_url": "https://api.github.com/repos/**********/REPO1/teams";,
    "topics": [
        "topic1",
        "topic2",
    ],
    "trees_url": 
"https://api.github.com/repos/**********/REPO1/git/trees{/sha}";,
    "updated_at": "2024-02-02T11:37:53Z",
    "url": "https://api.github.com/repos/**********/REPO1";,
    "visibility": "private",
    "watchers": 0,
    "watchers_count": 0
    },
    {
    "allow_forking": true,
    "archive_url": 
"https://api.github.com/repos/**********/REPO2/{archive_format}{/ref}";,
    "archived": true,
    "assignees_url": 
"https://api.github.com/repos/**********/REPO2/assignees{/user}";,
    "blobs_url": 
"https://api.github.com/repos/**********/REPO2/git/blobs{/sha}";,
    "branches_url": 
"https://api.github.com/repos/**********/REPO2/branches{/branch}";,
    "clone_url": "https://github.com/**********/REPO2.git";,
    "collaborators_url": 
"https://api.github.com/repos/**********/REPO2/collaborators{/collaborator}";,
    "comments_url": 
"https://api.github.com/repos/**********/REPO2/comments{/number}";,
    "commits_url": 
"https://api.github.com/repos/**********/REPO2/commits{/sha}";,
    "compare_url": 
"https://api.github.com/repos/**********/REPO2/compare/{base}...{head}";,
    "contents_url": 
"https://api.github.com/repos/**********/REPO2/contents/{+path}";,
    "contributors_url": 
"https://api.github.com/repos/**********/REPO2/contributors";,
    "created_at": "2023-06-15T11:42:52Z",
    "default_branch": "main",
    "deployments_url": 
"https://api.github.com/repos/**********/REPO2/deployments";,
    "description": "example repo structure for ds experience ~> ds solutions ",
    "disabled": false,
    "downloads_url": "https://api.github.com/repos/**********/REPO2/downloads";,
    "events_url": "https://api.github.com/repos/**********/REPO2/events";,
    "fork": true,
    "forks": 0,
    "forks_count": 0,
    "forks_url": "https://api.github.com/repos/**********/REPO2/forks";,
    "full_name": "**********/REPO2",
    "git_commits_url": 
"https://api.github.com/repos/**********/REPO2/git/commits{/sha}";,
    "git_refs_url": 
"https://api.github.com/repos/**********/REPO2/git/refs{/sha}";,
    "git_tags_url": 
"https://api.github.com/repos/**********/REPO2/git/tags{/sha}";,
    "git_url": "git://github.com/**********/REPO2.git",
    "has_downloads": true,
    "has_issues": false,
    "has_pages": false,
    "has_projects": true,
    "has_wiki": true,
    "homepage": null,
    "hooks_url": "https://api.github.com/repos/**********/REPO2/hooks";,
    "html_url": "https://github.com/**********/REPO2";,
    "id": 200000000,
    "issue_comment_url": 
"https://api.github.com/repos/**********/REPO2/issues/comments{/number}";,
    "issue_events_url": 
"https://api.github.com/repos/**********/REPO2/issues/events{/number}";,
    "issues_url": 
"https://api.github.com/repos/**********/REPO2/issues{/number}";,
    "keys_url": "https://api.github.com/repos/**********/REPO2/keys{/key_id}";,
    "labels_url": "https://api.github.com/repos/**********/REPO2/labels{/name}";,
    "language": null,
    "languages_url": "https://api.github.com/repos/**********/REPO2/languages";,
    "license": null,
    "merges_url": "https://api.github.com/repos/**********/REPO2/merges";,
    "milestones_url": 
"https://api.github.com/repos/**********/REPO2/milestones{/number}";,
    "mirror_url": null,
    "name": "REPO2",
    "node_id": "********",
    "notifications_url": 
"https://api.github.com/repos/**********/REPO2/notifications{?since,all,participating}";,
    "open_issues": 0,
    "open_issues_count": 0,
    "owner": {
        "avatar_url": "https://avatars.githubusercontent.com/u/200000?v=4";,
        "events_url": 
"https://api.github.com/users/**********/events{/privacy}";,
        "followers_url": "https://api.github.com/users/**********/followers";,
        "following_url": 
"https://api.github.com/users/**********/following{/other_user}";,
        "gists_url": "https://api.github.com/users/**********/gists{/gist_id}";,
        "gravatar_id": "",
        "html_url": "https://github.com/**********";,
        "id": 200000,
        "login": "**********",
        "node_id": "***********",
        "organizations_url": "https://api.github.com/users/**********/orgs";,
        "received_events_url": 
"https://api.github.com/users/**********/received_events";,
        "repos_url": "https://api.github.com/users/**********/repos";,
        "site_admin": false,
        "starred_url": 
"https://api.github.com/users/**********/starred{/owner}{/repo}";,
        "subscriptions_url": 
"https://api.github.com/users/**********/subscriptions";,
        "type": "Organization",
        "url": "https://api.github.com/users/**********";
    },
    "permissions": {
        "admin": false,
        "maintain": false,
        "pull": true,
        "push": false,
        "triage": false
    },
    "private": true,
    "pulls_url": "https://api.github.com/repos/**********/REPO2/pulls{/number}";,
    "pushed_at": "2023-06-08T15:48:53Z",
    "releases_url": 
"https://api.github.com/repos/**********/REPO2/releases{/id}";,
    "role_name": "read",
    "size": 792,
    "ssh_url": "[email protected]:**********/REPO2.git",
    "stargazers_count": 0,
    "stargazers_url": 
"https://api.github.com/repos/**********/REPO2/stargazers";,
    "statuses_url": 
"https://api.github.com/repos/**********/REPO2/statuses/{sha}";,
    "subscribers_url": 
"https://api.github.com/repos/**********/REPO2/subscribers";,
    "subscription_url": 
"https://api.github.com/repos/**********/REPO2/subscription";,
    "svn_url": "https://github.com/**********/REPO2";,
    "tags_url": "https://api.github.com/repos/**********/REPO2/tags";,
    "teams_url": "https://api.github.com/repos/**********/REPO2/teams";,
    "topics": [],
    "trees_url": 
"https://api.github.com/repos/**********/REPO2/git/trees{/sha}";,
    "updated_at": "2023-06-19T09:54:14Z",
    "url": "https://api.github.com/repos/**********/REPO2";,
    "visibility": "private",
    "watchers": 0,
    "watchers_count": 0
    },

--
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 
[email protected]<mailto:[email protected]>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/02a0ee32-794a-4821-9505-1f346802e6fen%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/02a0ee32-794a-4821-9505-1f346802e6fen%40googlegroups.com?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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/9EE65D7D-3EE0-47F0-A8FB-1BD14498AD18%40nist.gov.

Reply via email to