{"id":20686885,"url":"https://github.com/betrcode/ansible-append-list","last_synced_at":"2025-04-22T14:06:20.732Z","repository":{"id":48159054,"uuid":"71392959","full_name":"betrcode/ansible-append-list","owner":"betrcode","description":"How to append to a list in Ansible","archived":false,"fork":false,"pushed_at":"2023-01-21T13:55:15.000Z","size":7,"stargazers_count":49,"open_issues_count":0,"forks_count":22,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-22T14:06:06.915Z","etag":null,"topics":["ansible","ansible-playbook","append"],"latest_commit_sha":null,"homepage":"https://blog.crisp.se/2016/10/20/maxwenzin/how-to-append-to-lists-in-ansible","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/betrcode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-19T19:40:11.000Z","updated_at":"2025-03-18T14:50:31.000Z","dependencies_parsed_at":"2023-02-12T10:20:27.665Z","dependency_job_id":null,"html_url":"https://github.com/betrcode/ansible-append-list","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betrcode%2Fansible-append-list","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betrcode%2Fansible-append-list/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betrcode%2Fansible-append-list/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betrcode%2Fansible-append-list/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/betrcode","download_url":"https://codeload.github.com/betrcode/ansible-append-list/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250255709,"owners_count":21400410,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","ansible-playbook","append"],"created_at":"2024-11-16T22:37:15.421Z","updated_at":"2025-04-22T14:06:20.707Z","avatar_url":"https://github.com/betrcode.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# How to append to a list in Ansible\n\nIn this repository you can find examples of how to append things to lists in Ansible.\n\nThe original blog post can be found at:\n[https://blog.crisp.se/2016/10/20/maxwenzin/how-to-append-to-lists-in-ansible](https://blog.crisp.se/2016/10/20/maxwenzin/how-to-append-to-lists-in-ansible)\n\nThe examples make use of the builtin [set_fact module](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/set_fact_module.html).\n\n## How to run demonstration\n`ansible-playbook demo-append-list.yml`\n\nor (if the file is made executable)\n\n`./demo-append-list.yml`\n\n## Example output\n```shell\n\nmax@max-x1:~/ansible-append-list$ ansible-playbook demo-append-list.yml\n [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'\n\n\nPLAY [localhost] *******************************************************************************************************************************************************************************************\n\nTASK [Gathering Facts] *************************************************************************************************************************************************************************************\nok: [localhost]\n\nTASK [debug] ***********************************************************************************************************************************************************************************************\nok: [localhost] =\u003e {\n    \"msg\": \"Append list to list, or merge two lists\"\n}\n\nTASK [Setup two lists to be merged] ************************************************************************************************************************************************************************\nok: [localhost]\n\nTASK [debug] ***********************************************************************************************************************************************************************************************\nok: [localhost] =\u003e {\n    \"list_one\": [\n        1,\n        2,\n        3\n    ]\n}\n\nTASK [debug] ***********************************************************************************************************************************************************************************************\nok: [localhost] =\u003e {\n    \"list_two\": [\n        4,\n        5,\n        6\n    ]\n}\n\nTASK [Merge the two lists] *********************************************************************************************************************************************************************************\nok: [localhost]\n\nTASK [Demonstrate merged lists] ****************************************************************************************************************************************************************************\nok: [localhost] =\u003e {\n    \"lists_merged\": [\n        1,\n        2,\n        3,\n        4,\n        5,\n        6\n    ]\n}\n\nTASK [debug] ***********************************************************************************************************************************************************************************************\nok: [localhost] =\u003e {\n    \"msg\": \"Append/merge list of maps to list\"\n}\n\nTASK [Setup two lists to be merged] ************************************************************************************************************************************************************************\nok: [localhost]\n\nTASK [debug] ***********************************************************************************************************************************************************************************************\nok: [localhost] =\u003e {\n    \"list_one\": [\n        {\n            \"first_name\": \"John\",\n            \"last_name\": \"Doe\"\n        },\n        {\n            \"first_name\": \"Jane\",\n            \"last_name\": \"Doe\"\n        }\n    ]\n}\n\nTASK [debug] ***********************************************************************************************************************************************************************************************\nok: [localhost] =\u003e {\n    \"list_two\": [\n        {\n            \"first_name\": \"Douglas\",\n            \"last_name\": \"Adams\"\n        },\n        {\n            \"first_name\": \"Frederic\",\n            \"last_name\": \"Bastiat\"\n        }\n    ]\n}\n\nTASK [Merge the two lists of maps] *************************************************************************************************************************************************************************\nok: [localhost]\n\nTASK [Demonstrate merged lists] ****************************************************************************************************************************************************************************\nok: [localhost] =\u003e {\n    \"lists_merged\": [\n        {\n            \"first_name\": \"John\",\n            \"last_name\": \"Doe\"\n        },\n        {\n            \"first_name\": \"Jane\",\n            \"last_name\": \"Doe\"\n        },\n        {\n            \"first_name\": \"Douglas\",\n            \"last_name\": \"Adams\"\n        },\n        {\n            \"first_name\": \"Frederic\",\n            \"last_name\": \"Bastiat\"\n        }\n    ]\n}\n\nTASK [Initialize an empty list] ****************************************************************************************************************************************************************************\nok: [localhost]\n\nTASK [Setup a integer variable] ****************************************************************************************************************************************************************************\nok: [localhost]\n\nTASK [Append item to list] *********************************************************************************************************************************************************************************\nok: [localhost]\n\nTASK [debug] ***********************************************************************************************************************************************************************************************\nok: [localhost] =\u003e {\n    \"the_list\": [\n        5\n    ]\n}\n\nTASK [Append another item to the list] *********************************************************************************************************************************************************************\nok: [localhost]\n\nTASK [debug] ***********************************************************************************************************************************************************************************************\nok: [localhost] =\u003e {\n    \"the_list\": [\n        5,\n        6\n    ]\n}\n\nTASK [Initialize an empty list for our truths] *************************************************************************************************************************************************************\nok: [localhost]\n\nTASK [Setup a boolean variable] ****************************************************************************************************************************************************************************\nok: [localhost]\n\nTASK [Append boolean to list] ******************************************************************************************************************************************************************************\nok: [localhost]\n\nTASK [debug] ***********************************************************************************************************************************************************************************************\nok: [localhost] =\u003e {\n    \"my_thruths\": [\n        true\n    ]\n}\n\nTASK [Append another boolean to the list] ******************************************************************************************************************************************************************\nok: [localhost]\n\nTASK [debug] ***********************************************************************************************************************************************************************************************\nok: [localhost] =\u003e {\n    \"my_thruths\": [\n        true,\n        false\n    ]\n}\n\nTASK [Initialize an empty list for our strings] ************************************************************************************************************************************************************\nok: [localhost]\n\nTASK [Setup a string variable] *****************************************************************************************************************************************************************************\nok: [localhost]\n\nTASK [Append string to list] *******************************************************************************************************************************************************************************\nok: [localhost]\n\nTASK [debug] ***********************************************************************************************************************************************************************************************\nok: [localhost] =\u003e {\n    \"my_strings\": [\n        \"Max\"\n    ]\n}\n\nTASK [Append another item to the list] *********************************************************************************************************************************************************************\nok: [localhost]\n\nTASK [debug] ***********************************************************************************************************************************************************************************************\nok: [localhost] =\u003e {\n    \"my_strings\": [\n        \"Max\",\n        \"Power\"\n    ]\n}\n\nPLAY RECAP *************************************************************************************************************************************************************************************************\nlocalhost                  : ok=31   changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0\n```\n\n## Ansible version\n\nDemo built with Ansible version 2.6.5\nTested up to version 2.10.8\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbetrcode%2Fansible-append-list","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbetrcode%2Fansible-append-list","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbetrcode%2Fansible-append-list/lists"}