Skip to content

Instantly share code, notes, and snippets.

@strangeman
Created January 10, 2022 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save strangeman/53e4d71c335e649c7e38ec1ba3f5357b to your computer and use it in GitHub Desktop.
Save strangeman/53e4d71c335e649c7e38ec1ba3f5357b to your computer and use it in GitHub Desktop.
- name: Generate uniq path
set_fact:
site_tmp_path: "/tmp/npm/{{ ansible_date_time.iso8601_micro | to_uuid }}"
- name: Create a {{ site_tmp_path }} directory if it does not exist
file:
path: '{{ site_tmp_path }}'
state: directory
become: false
- name: get NPM package
ansible.builtin.shell: npm pack {{ site_npm_package }}@{{ site_version }} | xargs tar -xzf
args:
chdir: '{{ site_tmp_path }}'
become: false
- name: Upload static content to S3
command: "aws --region {{ aws_bucket_region }} s3 cp {{ site_tmp_path }}/package/{{ site_dir }}/ s3://{{ aws_site_bucket }}/{{ aws_key_prefix }} --recursive"
no_log: true
become: false
- name: Upload static content to S3 with cache_control params
command: "aws --region {{ aws_bucket_region }} s3 cp {{ site_tmp_path }}/package/{{ site_dir }}/ s3://{{ aws_site_bucket }}/{{ aws_key_prefix }} --recursive --cache-control 'public, max-age={{ item.maxage }}' --exclude '*' {% for pattern in item.patterns %} --include '{{ pattern }}' {% endfor %}"
no_log: true
become: false
with_items: "{{ cache_params }}"
when: cache_params is defined
- name: Include vars
include_vars:
file: "/tmp/distribution_id_{{ application_domain }}.yml"
ignore_errors: true
- name: Invalidations
command: "aws --region {{ aws_bucket_region }} cloudfront create-invalidation --distribution-id {{ aws_cloudfront_distribution_id }} --paths '/*'"
when: aws_cloudfront_distribution_id is defined
- name: Delete a {{ site_tmp_path }} directory
file:
path: '{{ site_tmp_path }}'
state: absent
become: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment