diff --git a/tasks/remount-off.yml b/tasks/remount-off.yml new file mode 100644 index 0000000..df1a901 --- /dev/null +++ b/tasks/remount-off.yml @@ -0,0 +1,36 @@ +# +# Remount partitions /usr and /tmp with their default options. +# This must be done after execution of remount-on.yml. +# +# Usage in playbooks: +# +# - include: inc/tasks/remount-off.yml +# vars: +# partitions: +# - "/tmp" +# - "/usr" +# + +--- + +- name: Get mount options for partitions + shell: mount |grep " {{ item }} " + register: mount + changed_when: False + failed_when: False + with_items: "{{ partitions }}" + +- name: Remount /usr if it is a partition and it is not mounted in ro + command: "mount -o remount {{ item.0 }}" + when: item.0 == "/usr" and item.1.rc == 0 and not item.1.stdout_lines.0|search("ro") + failed_when: False + with_together: + - "{{ partitions }}" + - "{{ mount.results }}" + +- name: Remount /tmp if it is a partition and it is not mounted in noexec + command: "mount -o remount {{ item.0 }}" + when: item.0 == "/tmp" and item.1.rc == 0 and not item.1.stdout_lines.0|search("noexec") + with_together: + - "{{ partitions }}" + - "{{ mount.results }}" diff --git a/tasks/remount-on.yml b/tasks/remount-on.yml new file mode 100644 index 0000000..37a2c38 --- /dev/null +++ b/tasks/remount-on.yml @@ -0,0 +1,36 @@ +# +# Remount partitions /usr and /tmp respectively with rw and exec. +# This must be done before trying to write on /usr or execute something in +# /tmp. +# +# Usage in playbooks: +# +# - include: inc/tasks/remount-on.yml +# vars: +# partitions: +# - "/tmp" +# - "/usr" +# + +--- + +- name: Get mount options for partitions + shell: mount |grep " {{ item }} " + register: mount + changed_when: False + failed_when: False + with_items: "{{ partitions }}" + +- name: Remount /usr if it is a partition and it is not mounted in rw + command: "mount -o remount,rw {{ item.0 }}" + when: item.0 == "/usr" and item.1.rc == 0 and not item.1.stdout_lines.0|search("rw") + with_together: + - "{{ partitions }}" + - "{{ mount.results }}" + +- name: Remount /tmp if it is a partition and it is mounted in noexec + command: "mount -o remount,exec {{ item.0 }}" + when: item.0 == "/tmp" and item.1.rc == 0 and item.1.stdout_lines.0|search("noexec") + with_together: + - "{{ partitions }}" + - "{{ mount.results }}"