ARG BASE_IMAGE

FROM ${BASE_IMAGE}

ARG APP_NAME
ARG ANSIBLE_ARGS

ADD . /etc/yandex/ansible/

RUN echo "- hosts: all\n  connection: local\n  gather_facts: yes\n  roles:\n    - ${APP_NAME}\n" | \
    sed 's/\\n/\n/g' \
    > /etc/yandex/ansible/build.yml
RUN cp /etc/yandex/ansible/build.yml /etc/yandex/ansible/pre-deploy.yml

# Run ansible for the first time to apply on-build-child tasks from
# parent roles (usually you don't need to re-run all of the tasks
# from them)
RUN . /usr/lib/yandex/ansible/bin/activate; \
    cd /etc/yandex/ansible/; \
    ansible-playbook \
        --diff \
        -i hosts \
        --tags on-build-child,untagged \
        ${ANSIBLE_ARGS} \
        build.yml
