Skip to content

Commit 2c76623

Browse files
committed
Preserve user, group, and mode when copying around resolv.conf
1 parent 1b662af commit 2c76623

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

molecule/default/unmount.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,30 @@
44
become: true
55
become_method: ansible.builtin.sudo
66
tasks:
7-
- name: Copy /etc/resolv.conf to /tmp
7+
- name: >-
8+
Grab the current owner, group, and mode for the existing
9+
/etc/resolv.conf
10+
ansible.builtin.stat:
11+
follow: true
12+
path: /etc/resolv.conf
13+
register: resolv_conf
14+
- name: Copy /etc/resolv.conf to /tmp, preserving owner, group, and mode
815
ansible.builtin.copy:
916
dest: /tmp/resolv.conf
10-
group: root
11-
mode: u=rw,g=r,o=r
12-
owner: root
17+
group: "{{ resolv_conf.stat.gid }}"
18+
mode: "{{ resolv_conf.stat.mode }}"
19+
owner: "{{ resolv_conf.stat.uid }}"
1320
remote_src: true
1421
src: /etc/resolv.conf
1522
- name: Unmount /etc/resolv.conf
1623
ansible.posix.mount:
1724
path: /etc/resolv.conf
1825
state: unmounted
19-
- name: Copy /tmp/resolv.conf to /etc
26+
- name: Copy /tmp/resolv.conf to /etc, preserving owner, group, and mode
2027
ansible.builtin.copy:
2128
dest: /etc/resolv.conf
22-
group: root
23-
mode: u=rw,g=r,o=r
24-
owner: root
29+
group: "{{ resolv_conf.stat.gid }}"
30+
mode: "{{ resolv_conf.stat.mode }}"
31+
owner: "{{ resolv_conf.stat.uid }}"
2532
remote_src: true
2633
src: /tmp/resolv.conf

0 commit comments

Comments
 (0)