--- - name: Public Profile Capture hosts: all become: yes ############################################### # Playbook to capture public profile ############################################### tasks: ############################################### # Check System Architecture ############################################### - name: Install Apps - Check CPU Arch shell: "dpkg --print-architecture" register: cpu_architecture_output - name: Set cpu_architecture variable set_fact: cpu_architecture: "{{ cpu_architecture_output.stdout_lines[0] }}" - name: Display Architecture debug: msg: "CPU Architecture: {{ cpu_architecture }}" ############################################### # Determine Public User Account Name ############################################### - name: Get User Account Folders shell: 'cat /opt/cosmos/local-user' register: user_file_contents - name: Set User Variable set_fact: public_user: "{{ user_file_contents.stdout }}" - name: Display Result debug: msg: "Public user account: {{ public_user }}" ############################################### # Mount remote profile archive folder ############################################### - name: Public Capture - Remote Profile Folder Check file: path: "/opt/cosmos/profile" state: directory owner: root group: root mode: '0755' - name: Public Capture - Local Archive Folder Check file: path: "/opt/cosmos/archives" state: directory owner: root group: root mode: '0755' - name: Public Capture - Mount network share mount: path: "/opt/cosmos/profile" src: "//172.25.1.10/behemoth/ansible-files/profile" fstype: cifs opts: "username=behemoth,password={{ saturn_behemoth }}" state: mounted ############################################### # Archive user folder ############################################### - name: Public Capture - Generate Archive Exclusion List copy: dest: /opt/cosmos/archives/user-exclude.txt content: | .cache .local/share/user-places.xbel .local/share/user-places.xbel.bak .local/share/user-places.xbel.tbcache .local/share/RecentDocuments .config/google-chrome .config/chromium .config/session .bash_history - name: Public Capture - Create Profile Tarball shell: "tar --use-compress-program=pigz --exclude-from=/opt/cosmos/archives/user-exclude.txt -cf /opt/cosmos/archives/user.tar.gz -C /home/{{ public_user }} ." ############################################### # Copy archive to network and remove local copy ############################################### - name: Public Capture - Get Archive Sizes shell: "ls -lah /opt/cosmos/archives | grep tar | awk '{print $9 \": \" $5}'" register: archive_size_output - name: Public Capture - Show Archive Sizes debug: msg: "{{ archive_size_output.stdout_lines }}" - name: Public Capture - Copy archives shell: "cp /opt/cosmos/archives/user.tar.gz /opt/cosmos/profile/user_{{ cpu_architecture }}.tar.gz" - name: Public Capture - Delete local files shell: | rm /opt/cosmos/archives/user.tar.gz rm /opt/cosmos/archives/user-exclude.txt ############################################### # Unmount network share ############################################### - name: Public Capture - Unmount network share mount: path: "/opt/cosmos/profile/" state: absent - name: Public Capture - Make sure mountpoint is gone from fstab lineinfile: path: /etc/fstab regexp: '\/opt\/cosmos\/profile' state: absent - name: Public Capture - Manually Unmount Share shell: umount /opt/cosmos/profile ...