How can I access the tags and skip-tags passed via command line to an ansible playbook at run time?
I am trying to achieve a with_items loop that can skip or include items based on tag/skip-tag using a when clause. This previous SO question touches on the same topic but takes a different approach.
I would evaluate the existence of a tag per iteration.
For example:
-  name: Build docker images
    docker_image:
        name: "{{item.name}}"
        path: "{{build_folder}}/dockerfiles/{{item.name}}"
        dockerfile: "{{item.name}}.Dockerfile"
        state: build
        tag: "{{private_docker_registry}}/{{item.name}}"
    when: "{{ansible_host_vars['tags'][image1]}}" is defined
    with_items: 
        - image1
        - image2
        - image3
                Since 2.5, ansible added some magic variables to access at runtime. Some of them is ansible_run_tags. It seems to be what you needed.
Ref: Ansible 2.5 change logs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With