Skip to content

Instantly share code, notes, and snippets.

@juanje
Last active February 21, 2021 10:52
Show Gist options
  • Save juanje/4cf378efcb0748ad005fe52ea42212f6 to your computer and use it in GitHub Desktop.
Save juanje/4cf378efcb0748ad005fe52ea42212f6 to your computer and use it in GitHub Desktop.

Revisions

  1. juanje revised this gist Feb 21, 2021. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion compose_variables.yml
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@
    msg: "{{ item }}"
    loop: "{{ api_urls }}"

    - name: Show the list of resources
    - name: Show the list of api_resources
    debug:
    msg: "{{ item }}"
    loop: "{{ api_resources }}"
    2 changes: 1 addition & 1 deletion output.sh
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ ok: [localhost] => (item=https://api.example.com/v3) =>
    ok: [localhost] => (item=https://api.example.com/v5) =>
    msg: https://api.example.com/v5

    TASK [Show the list of resources] ************************************************************************************************************************************************************************************************************
    TASK [Show the list of api_resources] ************************************************************************************************************************************************************************************************************
    ok: [localhost] => (item=resource_num_1) =>
    msg: resource_num_1
    ok: [localhost] => (item=resource_num_2) =>
  2. juanje revised this gist Feb 21, 2021. 2 changed files with 41 additions and 33 deletions.
    10 changes: 8 additions & 2 deletions compose_variables.yml
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    ---
    - hosts: localhost
    - name: Compose variables and merge lists
    hosts: localhost
    connection: local
    gather_facts: no

    @@ -28,7 +29,12 @@
    msg: "{{ item }}"
    loop: "{{ api_urls }}"

    - name: Ensure the toolbox image is at local directory
    - name: Show the list of resources
    debug:
    msg: "{{ item }}"
    loop: "{{ api_resources }}"

    - name: Show the WHAT resources get from WHERE
    debug:
    msg: "GET: {{ item.1 }} FROM: {{ item.0 }}"
    # Merge api_urls and api_resources lists using the zip() filter
    64 changes: 33 additions & 31 deletions output.sh
    Original file line number Diff line number Diff line change
    @@ -1,40 +1,42 @@
    $ ansible-playbook compose_variables.yml
    $ ansible-playbook compose_variables.yml

    PLAY [localhost] *********************************************************************************************************************************************************************************************************************************
    PLAY [Compose variables and merge lists] *****************************************************************************************************************************************************************************************************

    TASK [Compose the list of api_urls] **************************************************************************************************************************************************************************************************************
    TASK [Compose the list of api_urls] **********************************************************************************************************************************************************************************************************
    ok: [localhost] => (item=1)
    ok: [localhost] => (item=2)
    ok: [localhost] => (item=3)
    ok: [localhost] => (item=5)

    TASK [Show the list of api_urls] *****************************************************************************************************************************************************************************************************************
    ok: [localhost] => (item=https://api.example.com/v1) => {
    "msg": "https://api.example.com/v1"
    }
    ok: [localhost] => (item=https://api.example.com/v2) => {
    "msg": "https://api.example.com/v2"
    }
    ok: [localhost] => (item=https://api.example.com/v3) => {
    "msg": "https://api.example.com/v3"
    }
    ok: [localhost] => (item=https://api.example.com/v5) => {
    "msg": "https://api.example.com/v5"
    }
    TASK [Show the list of api_urls] *************************************************************************************************************************************************************************************************************
    ok: [localhost] => (item=https://api.example.com/v1) =>
    msg: https://api.example.com/v1
    ok: [localhost] => (item=https://api.example.com/v2) =>
    msg: https://api.example.com/v2
    ok: [localhost] => (item=https://api.example.com/v3) =>
    msg: https://api.example.com/v3
    ok: [localhost] => (item=https://api.example.com/v5) =>
    msg: https://api.example.com/v5

    TASK [Ensure the toolbox image is at local directory] ********************************************************************************************************************************************************************************************
    ok: [localhost] => (item=['https://api.example.com/v1', 'resource_num_1']) => {
    "msg": "GET: resource_num_1 FROM: https://api.example.com/v1"
    }
    ok: [localhost] => (item=['https://api.example.com/v2', 'resource_num_2']) => {
    "msg": "GET: resource_num_2 FROM: https://api.example.com/v2"
    }
    ok: [localhost] => (item=['https://api.example.com/v3', 'resource_num_3']) => {
    "msg": "GET: resource_num_3 FROM: https://api.example.com/v3"
    }
    ok: [localhost] => (item=['https://api.example.com/v5', 'resource_num_5']) => {
    "msg": "GET: resource_num_5 FROM: https://api.example.com/v5"
    }
    TASK [Show the list of resources] ************************************************************************************************************************************************************************************************************
    ok: [localhost] => (item=resource_num_1) =>
    msg: resource_num_1
    ok: [localhost] => (item=resource_num_2) =>
    msg: resource_num_2
    ok: [localhost] => (item=resource_num_3) =>
    msg: resource_num_3
    ok: [localhost] => (item=resource_num_5) =>
    msg: resource_num_5

    PLAY RECAP ***************************************************************************************************************************************************************************************************************************************
    localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
    TASK [Show the WHAT resources get from WHERE] ************************************************************************************************************************************************************************************************
    ok: [localhost] => (item=['https://api.example.com/v1', 'resource_num_1']) =>
    msg: 'GET: resource_num_1 FROM: https://api.example.com/v1'
    ok: [localhost] => (item=['https://api.example.com/v2', 'resource_num_2']) =>
    msg: 'GET: resource_num_2 FROM: https://api.example.com/v2'
    ok: [localhost] => (item=['https://api.example.com/v3', 'resource_num_3']) =>
    msg: 'GET: resource_num_3 FROM: https://api.example.com/v3'
    ok: [localhost] => (item=['https://api.example.com/v5', 'resource_num_5']) =>
    msg: 'GET: resource_num_5 FROM: https://api.example.com/v5'

    PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
    localhost : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  3. juanje revised this gist Aug 11, 2020. 1 changed file with 12 additions and 2 deletions.
    14 changes: 12 additions & 2 deletions compose_variables.yml
    Original file line number Diff line number Diff line change
    @@ -9,17 +9,27 @@
    - 2
    - 3
    - 5
    api_url: 'https://api.example.com'
    api_url: "https://api.example.com"
    api_resource: "resource_num_"
    api_resources: []
    api_urls: []

    pre_tasks:
    - name: Compose the list of api_urls
    set_fact:
    # [A] = [A] + [item]
    api_urls: "{{ api_urls }} + [ '{{ api_url }}/v{{ item }}' ]"
    api_resources: "{{ api_resources }} + [ '{{ api_resource }}{{ item }}' ]"
    loop: "{{ api_versions }}"

    tasks:
    - name: Show the list of api_urls
    debug:
    msg: '{{ item }}'
    msg: "{{ item }}"
    loop: "{{ api_urls }}"

    - name: Ensure the toolbox image is at local directory
    debug:
    msg: "GET: {{ item.1 }} FROM: {{ item.0 }}"
    # Merge api_urls and api_resources lists using the zip() filter
    loop: "{{ api_urls | zip(api_resources) | list }}"
  4. juanje revised this gist Aug 11, 2020. 2 changed files with 21 additions and 7 deletions.
    2 changes: 1 addition & 1 deletion compose_variables.yml
    Original file line number Diff line number Diff line change
    @@ -22,4 +22,4 @@
    - name: Show the list of api_urls
    debug:
    msg: '{{ item }}'
    loop: "{{ api_urls }}"
    loop: "{{ api_urls }}"
    26 changes: 20 additions & 6 deletions output.sh
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    $ ansible-playbook compose_variables.yml
    $ ansible-playbook compose_variables.yml

    PLAY [localhost] *********************************************************************************************************************************************************************************************************************************

    TASK [Compose the list of api_urls] **************************************************************************************************************************************************************************************************************
    ok: [localhost] => (item=v1)
    ok: [localhost] => (item=v2)
    ok: [localhost] => (item=v3)
    ok: [localhost] => (item=v5)
    ok: [localhost] => (item=1)
    ok: [localhost] => (item=2)
    ok: [localhost] => (item=3)
    ok: [localhost] => (item=5)

    TASK [Show the list of api_urls] *****************************************************************************************************************************************************************************************************************
    ok: [localhost] => (item=https://api.example.com/v1) => {
    @@ -22,5 +22,19 @@ ok: [localhost] => (item=https://api.example.com/v5) => {
    "msg": "https://api.example.com/v5"
    }

    TASK [Ensure the toolbox image is at local directory] ********************************************************************************************************************************************************************************************
    ok: [localhost] => (item=['https://api.example.com/v1', 'resource_num_1']) => {
    "msg": "GET: resource_num_1 FROM: https://api.example.com/v1"
    }
    ok: [localhost] => (item=['https://api.example.com/v2', 'resource_num_2']) => {
    "msg": "GET: resource_num_2 FROM: https://api.example.com/v2"
    }
    ok: [localhost] => (item=['https://api.example.com/v3', 'resource_num_3']) => {
    "msg": "GET: resource_num_3 FROM: https://api.example.com/v3"
    }
    ok: [localhost] => (item=['https://api.example.com/v5', 'resource_num_5']) => {
    "msg": "GET: resource_num_5 FROM: https://api.example.com/v5"
    }

    PLAY RECAP ***************************************************************************************************************************************************************************************************************************************
    localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
    localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  5. juanje revised this gist Aug 11, 2020. 2 changed files with 34 additions and 46 deletions.
    39 changes: 17 additions & 22 deletions compose_variables.yml
    Original file line number Diff line number Diff line change
    @@ -1,30 +1,25 @@
    ---
    - hosts: all
    gather_facts: false
    - hosts: localhost
    connection: local
    gather_facts: no

    vars:
    fedora_versions:
    - 29
    - 31
    - 33
    registry_url: 'registry.fedoraproject.org'
    toolbox_image: 'fedora-toolbox'
    toolbox_dirs: []
    registry_urls: []
    api_versions:
    - 1
    - 2
    - 3
    - 5
    api_url: 'https://api.example.com'
    api_urls: []

    pre_tasks:
    - set_fact:
    toolbox_dirs: "{{ toolbox_dirs }} + [ '{{ toolbox_image }}-{{ item }}' ]"
    registry_urls: "{{ registry_urls }} + [ '{{ registry_url }}/f{{ item }}/{{ toolbox_image }}:{{ item }}' ]"
    loop: "{{ fedora_versions }}"
    - name: Compose the list of api_urls
    set_fact:
    api_urls: "{{ api_urls }} + [ '{{ api_url }}/v{{ item }}' ]"
    loop: "{{ api_versions }}"

    tasks:
    - name: Ensure a directory exist to store the toolbox images
    - name: Show the list of api_urls
    debug:
    msg: 'mkdir ./{{ item }}'
    loop: "{{ toolbox_dirs }}"

    - name: Ensure the toolbox image is at local directory
    debug:
    msg: "skopeo copy docker://{{ item.0 }} dir:{{ item.1 }}"
    loop: "{{ registry_urls | zip(toolbox_dirs) | list }}"
    msg: '{{ item }}'
    loop: "{{ api_urls }}"
    41 changes: 17 additions & 24 deletions output.sh
    Original file line number Diff line number Diff line change
    @@ -1,33 +1,26 @@
    $ ansible-playbook -i localhost, -c local compose_variables.yml
    $ ansible-playbook compose_variables.yml

    PLAY [localhost *********************************************************************************************************************************************************************************************************************************
    PLAY [localhost] *********************************************************************************************************************************************************************************************************************************

    TASK [set_fact] **********************************************************************************************************************************************************************************************************************************
    ok: [localhost] => (item=29)
    ok: [localhost] => (item=31)
    ok: [localhost] => (item=33)
    TASK [Compose the list of api_urls] **************************************************************************************************************************************************************************************************************
    ok: [localhost] => (item=v1)
    ok: [localhost] => (item=v2)
    ok: [localhost] => (item=v3)
    ok: [localhost] => (item=v5)

    TASK [Ensure a directory exist to store the toolbox images] **************************************************************************************************************************************************************************************
    ok: [localhost] => (item=fedora-toolbox-29) => {
    "msg": "mkdir ./fedora-toolbox-29"
    TASK [Show the list of api_urls] *****************************************************************************************************************************************************************************************************************
    ok: [localhost] => (item=https://api.example.com/v1) => {
    "msg": "https://api.example.com/v1"
    }
    ok: [localhost] => (item=fedora-toolbox-31) => {
    "msg": "mkdir ./fedora-toolbox-31"
    ok: [localhost] => (item=https://api.example.com/v2) => {
    "msg": "https://api.example.com/v2"
    }
    ok: [localhost] => (item=fedora-toolbox-33) => {
    "msg": "mkdir ./fedora-toolbox-33"
    ok: [localhost] => (item=https://api.example.com/v3) => {
    "msg": "https://api.example.com/v3"
    }

    TASK [Ensure the toolbox image is at local directory] ********************************************************************************************************************************************************************************************
    ok: [localhost] => (item=['registry.fedoraproject.org/f29/fedora-toolbox:29', 'fedora-toolbox-29']) => {
    "msg": "skopeo copy docker://registry.fedoraproject.org/f29/fedora-toolbox:29 dir:fedora-toolbox-29"
    }
    ok: [localhost] => (item=['registry.fedoraproject.org/f31/fedora-toolbox:31', 'fedora-toolbox-31']) => {
    "msg": "skopeo copy docker://registry.fedoraproject.org/f31/fedora-toolbox:31 dir:fedora-toolbox-31"
    }
    ok: [localhost] => (item=['registry.fedoraproject.org/f33/fedora-toolbox:33', 'fedora-toolbox-33']) => {
    "msg": "skopeo copy docker://registry.fedoraproject.org/f33/fedora-toolbox:33 dir:fedora-toolbox-33"
    ok: [localhost] => (item=https://api.example.com/v5) => {
    "msg": "https://api.example.com/v5"
    }

    PLAY RECAP ***************************************************************************************************************************************************************************************************************************************
    localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
    localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  6. juanje revised this gist Aug 10, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions compose_variables.yml
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@
    pre_tasks:
    - set_fact:
    toolbox_dirs: "{{ toolbox_dirs }} + [ '{{ toolbox_image }}-{{ item }}' ]"
    registry_urls: "{{ registry_urls }} + [ '{{ registry_url }}/f{{ item }}/{{ toolbox_image }}:{{item }}' ]"
    registry_urls: "{{ registry_urls }} + [ '{{ registry_url }}/f{{ item }}/{{ toolbox_image }}:{{ item }}' ]"
    loop: "{{ fedora_versions }}"

    tasks:
    @@ -27,4 +27,4 @@
    - name: Ensure the toolbox image is at local directory
    debug:
    msg: "skopeo copy docker://{{ item.0 }} dir:{{ item.1 }}"
    loop: "{{ registry_urls|zip(toolbox_dirs)|list }}"
    loop: "{{ registry_urls | zip(toolbox_dirs) | list }}"
  7. juanje revised this gist Aug 7, 2020. 1 changed file with 11 additions and 11 deletions.
    22 changes: 11 additions & 11 deletions output.sh
    Original file line number Diff line number Diff line change
    @@ -1,33 +1,33 @@
    $ ansible-playbook -i localhost, -c local compose_variables.yml

    PLAY [127.0.0.1] *********************************************************************************************************************************************************************************************************************************
    PLAY [localhost *********************************************************************************************************************************************************************************************************************************

    TASK [set_fact] **********************************************************************************************************************************************************************************************************************************
    ok: [127.0.0.1] => (item=29)
    ok: [127.0.0.1] => (item=31)
    ok: [127.0.0.1] => (item=33)
    ok: [localhost] => (item=29)
    ok: [localhost] => (item=31)
    ok: [localhost] => (item=33)

    TASK [Ensure a directory exist to store the toolbox images] **************************************************************************************************************************************************************************************
    ok: [127.0.0.1] => (item=fedora-toolbox-29) => {
    ok: [localhost] => (item=fedora-toolbox-29) => {
    "msg": "mkdir ./fedora-toolbox-29"
    }
    ok: [127.0.0.1] => (item=fedora-toolbox-31) => {
    ok: [localhost] => (item=fedora-toolbox-31) => {
    "msg": "mkdir ./fedora-toolbox-31"
    }
    ok: [127.0.0.1] => (item=fedora-toolbox-33) => {
    ok: [localhost] => (item=fedora-toolbox-33) => {
    "msg": "mkdir ./fedora-toolbox-33"
    }

    TASK [Ensure the toolbox image is at local directory] ********************************************************************************************************************************************************************************************
    ok: [127.0.0.1] => (item=['registry.fedoraproject.org/f29/fedora-toolbox:29', 'fedora-toolbox-29']) => {
    ok: [localhost] => (item=['registry.fedoraproject.org/f29/fedora-toolbox:29', 'fedora-toolbox-29']) => {
    "msg": "skopeo copy docker://registry.fedoraproject.org/f29/fedora-toolbox:29 dir:fedora-toolbox-29"
    }
    ok: [127.0.0.1] => (item=['registry.fedoraproject.org/f31/fedora-toolbox:31', 'fedora-toolbox-31']) => {
    ok: [localhost] => (item=['registry.fedoraproject.org/f31/fedora-toolbox:31', 'fedora-toolbox-31']) => {
    "msg": "skopeo copy docker://registry.fedoraproject.org/f31/fedora-toolbox:31 dir:fedora-toolbox-31"
    }
    ok: [127.0.0.1] => (item=['registry.fedoraproject.org/f33/fedora-toolbox:33', 'fedora-toolbox-33']) => {
    ok: [localhost] => (item=['registry.fedoraproject.org/f33/fedora-toolbox:33', 'fedora-toolbox-33']) => {
    "msg": "skopeo copy docker://registry.fedoraproject.org/f33/fedora-toolbox:33 dir:fedora-toolbox-33"
    }

    PLAY RECAP ***************************************************************************************************************************************************************************************************************************************
    127.0.0.1 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
    localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  8. juanje revised this gist Aug 7, 2020. 2 changed files with 2 additions and 3 deletions.
    3 changes: 1 addition & 2 deletions compose_variables.yml
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,5 @@
    ---
    - hosts: 127.0.0.1
    connection: local
    - hosts: all
    gather_facts: false

    vars:
    2 changes: 1 addition & 1 deletion output.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    $ ansible-playbook -i 127.0.0.1, compose_variables.yml
    $ ansible-playbook -i localhost, -c local compose_variables.yml

    PLAY [127.0.0.1] *********************************************************************************************************************************************************************************************************************************

  9. juanje renamed this gist Aug 5, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. juanje renamed this gist Aug 5, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  11. juanje renamed this gist Aug 5, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  12. juanje revised this gist Aug 5, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions compose_variables.yml
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    ---
    - hosts: 127.0.0.1
    connection: local
    gather_facts: false
  13. juanje created this gist Aug 5, 2020.
    30 changes: 30 additions & 0 deletions compose_variables.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    - hosts: 127.0.0.1
    connection: local
    gather_facts: false

    vars:
    fedora_versions:
    - 29
    - 31
    - 33
    registry_url: 'registry.fedoraproject.org'
    toolbox_image: 'fedora-toolbox'
    toolbox_dirs: []
    registry_urls: []

    pre_tasks:
    - set_fact:
    toolbox_dirs: "{{ toolbox_dirs }} + [ '{{ toolbox_image }}-{{ item }}' ]"
    registry_urls: "{{ registry_urls }} + [ '{{ registry_url }}/f{{ item }}/{{ toolbox_image }}:{{item }}' ]"
    loop: "{{ fedora_versions }}"

    tasks:
    - name: Ensure a directory exist to store the toolbox images
    debug:
    msg: 'mkdir ./{{ item }}'
    loop: "{{ toolbox_dirs }}"

    - name: Ensure the toolbox image is at local directory
    debug:
    msg: "skopeo copy docker://{{ item.0 }} dir:{{ item.1 }}"
    loop: "{{ registry_urls|zip(toolbox_dirs)|list }}"
    33 changes: 33 additions & 0 deletions output.sh.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    $ ansible-playbook -i 127.0.0.1, compose_variables.yml

    PLAY [127.0.0.1] *********************************************************************************************************************************************************************************************************************************

    TASK [set_fact] **********************************************************************************************************************************************************************************************************************************
    ok: [127.0.0.1] => (item=29)
    ok: [127.0.0.1] => (item=31)
    ok: [127.0.0.1] => (item=33)

    TASK [Ensure a directory exist to store the toolbox images] **************************************************************************************************************************************************************************************
    ok: [127.0.0.1] => (item=fedora-toolbox-29) => {
    "msg": "mkdir ./fedora-toolbox-29"
    }
    ok: [127.0.0.1] => (item=fedora-toolbox-31) => {
    "msg": "mkdir ./fedora-toolbox-31"
    }
    ok: [127.0.0.1] => (item=fedora-toolbox-33) => {
    "msg": "mkdir ./fedora-toolbox-33"
    }

    TASK [Ensure the toolbox image is at local directory] ********************************************************************************************************************************************************************************************
    ok: [127.0.0.1] => (item=['registry.fedoraproject.org/f29/fedora-toolbox:29', 'fedora-toolbox-29']) => {
    "msg": "skopeo copy docker://registry.fedoraproject.org/f29/fedora-toolbox:29 dir:fedora-toolbox-29"
    }
    ok: [127.0.0.1] => (item=['registry.fedoraproject.org/f31/fedora-toolbox:31', 'fedora-toolbox-31']) => {
    "msg": "skopeo copy docker://registry.fedoraproject.org/f31/fedora-toolbox:31 dir:fedora-toolbox-31"
    }
    ok: [127.0.0.1] => (item=['registry.fedoraproject.org/f33/fedora-toolbox:33', 'fedora-toolbox-33']) => {
    "msg": "skopeo copy docker://registry.fedoraproject.org/f33/fedora-toolbox:33 dir:fedora-toolbox-33"
    }

    PLAY RECAP ***************************************************************************************************************************************************************************************************************************************
    127.0.0.1 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0