From 8027bc53359e8006b94802468f7b60d89c73b61b Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 25 Aug 2022 06:43:07 +0200 Subject: [PATCH] filesystem: create temp directory outside /tmp to avoid problems with tmpfs. (#5182) --- .../targets/filesystem/meta/main.yml | 2 +- .../handlers/main.yml | 10 +++++++++ .../tasks/default-cleanup.yml | 10 +++++++++ .../tasks/default.yml | 22 +++++++++++++++++++ .../tasks/main.yml | 20 +++++++++++++++++ 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tests/integration/targets/setup_remote_tmp_dir_outside_tmp/handlers/main.yml create mode 100644 tests/integration/targets/setup_remote_tmp_dir_outside_tmp/tasks/default-cleanup.yml create mode 100644 tests/integration/targets/setup_remote_tmp_dir_outside_tmp/tasks/default.yml create mode 100644 tests/integration/targets/setup_remote_tmp_dir_outside_tmp/tasks/main.yml diff --git a/tests/integration/targets/filesystem/meta/main.yml b/tests/integration/targets/filesystem/meta/main.yml index ca1915e05c..d3facee4f2 100644 --- a/tests/integration/targets/filesystem/meta/main.yml +++ b/tests/integration/targets/filesystem/meta/main.yml @@ -5,4 +5,4 @@ dependencies: - setup_pkg_mgr - - setup_remote_tmp_dir + - setup_remote_tmp_dir_outside_tmp diff --git a/tests/integration/targets/setup_remote_tmp_dir_outside_tmp/handlers/main.yml b/tests/integration/targets/setup_remote_tmp_dir_outside_tmp/handlers/main.yml new file mode 100644 index 0000000000..f1c55b04f3 --- /dev/null +++ b/tests/integration/targets/setup_remote_tmp_dir_outside_tmp/handlers/main.yml @@ -0,0 +1,10 @@ +--- +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +- name: delete temporary directory + include_tasks: default-cleanup.yml + +- name: delete temporary directory (windows) + include_tasks: windows-cleanup.yml diff --git a/tests/integration/targets/setup_remote_tmp_dir_outside_tmp/tasks/default-cleanup.yml b/tests/integration/targets/setup_remote_tmp_dir_outside_tmp/tasks/default-cleanup.yml new file mode 100644 index 0000000000..e19d903e6b --- /dev/null +++ b/tests/integration/targets/setup_remote_tmp_dir_outside_tmp/tasks/default-cleanup.yml @@ -0,0 +1,10 @@ +--- +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +- name: delete temporary directory + file: + path: "{{ remote_tmp_dir }}" + state: absent + no_log: yes diff --git a/tests/integration/targets/setup_remote_tmp_dir_outside_tmp/tasks/default.yml b/tests/integration/targets/setup_remote_tmp_dir_outside_tmp/tasks/default.yml new file mode 100644 index 0000000000..0aef57f99c --- /dev/null +++ b/tests/integration/targets/setup_remote_tmp_dir_outside_tmp/tasks/default.yml @@ -0,0 +1,22 @@ +--- +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +- name: create ~/tmp + file: + path: '~/tmp' + state: directory + +- name: create temporary directory + tempfile: + state: directory + suffix: .test + path: ~/tmp + register: remote_tmp_dir + notify: + - delete temporary directory + +- name: record temporary directory + set_fact: + remote_tmp_dir: "{{ remote_tmp_dir.path }}" diff --git a/tests/integration/targets/setup_remote_tmp_dir_outside_tmp/tasks/main.yml b/tests/integration/targets/setup_remote_tmp_dir_outside_tmp/tasks/main.yml new file mode 100644 index 0000000000..6632cc8489 --- /dev/null +++ b/tests/integration/targets/setup_remote_tmp_dir_outside_tmp/tasks/main.yml @@ -0,0 +1,20 @@ +--- +#################################################################### +# WARNING: These are designed specifically for Ansible tests # +# and should not be used as examples of how to write Ansible roles # +#################################################################### + +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +- name: make sure we have the ansible_os_family and ansible_distribution_version facts + setup: + gather_subset: distribution + when: ansible_facts == {} + +- include_tasks: "{{ lookup('first_found', files)}}" + vars: + files: + - "{{ ansible_os_family | lower }}.yml" + - "default.yml"