Skip to content

Commit

Permalink
Check if ~/,bashrc exist before diffing
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscostadsc committed Dec 12, 2023
1 parent d2437f0 commit 2beea39
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions roles/bash/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,25 @@
dest: "{{ home_folder }}"
mode: preserve

- name: Check ~/.bashrc exists
ansible.builtin.:
path: "{{ home_folder }}/.bashrc"
register: bashrc_exists

# yamllint disable rule:indentation
- name: Register .bashrc content
when: bashrc_exists.stat.exists
ansible.builtin.shell: |
set -o pipefail
grep -qF "$(cat {{ lookup('file', 'files/.bashrc') }} | tr '\n' '\01')" \
<<< "$(cat {{ home_folder }}/.bashrc | tr '\n' '\01')"
register: bashrc_check
register: bashrc_content_check
failed_when: false
changed_when: false
# yamllint enable rule:indentation

- name: Copy .bashrc to home folder
when: bashrc_check.rc != 0 # only copy if bash bashrc is different
when: not bashrc_exists.stat.exists or bashrc_content_check.rc != 0
ansible.builtin.copy:
src: files/.bashrc
dest: "{{ home_folder }}"
Expand Down

0 comments on commit 2beea39

Please sign in to comment.