--- - name: ensure build work dir exists become: yes file: path: "{{build_work_dir}}" state: "directory" owner: "{{ansible_user}}" group: "{{ansible_user}}" mode: "0755" - name: install cargo become: yes apt: name="cargo" - name: unarchive bin unarchive: remote_src: yes src: "{{bin_tar}}" dest: "{{build_work_dir}}/" creates: "{{bin_build_dir}}" - name: check if bin build exists stat: path: "{{bin_srv_dir}}/bin-{{bin_version}}.tar.gz" register: build_file - name: build bin command: "cargo build --release" args: chdir: "{{bin_build_dir}}" # Keep the cargo cache on build_work_dir (the SSD) instead of the SD card. environment: CARGO_HOME: "{{build_work_dir}}/.cargo" when: not build_file.stat.exists - name: create build server dir become: yes file: path: "{{bin_srv_dir}}" mode: "0755" state: "directory" - name: create gz archive of bin become: yes archive: path: "{{bin_build_dir}}/target/release/bin" dest: "{{bin_srv_dir}}/bin-{{bin_version}}.tar.gz" format: "gz" # force a real tar for the single binary; the module otherwise gzips a lone # file into a bare .gz that the server's unarchive can't extract. force_archive: true when: not build_file.stat.exists