- 1 year ago
Create directory and save output files in that directory
To create a directory and save output files in that directory using Ansible, you can utilize the ansible.builtin.file
module and use the path
parameter to specify the directory path. Here's an example playbook:
yaml---
- name: Create directory and save output files
hosts: localhost
gather_facts: false
tasks:
- name: Create directory
ansible.builtin.file:
path: /path/to/directory
state: directory
- name: Save output files
ansible.builtin.copy:
content: "Output file 1"
dest: /path/to/directory/output1.txt
- name: Save another output file
ansible.builtin.copy:
content: "Output file 2"
dest: /path/to/directory/output2.txt
Replace /path/to/directory
with the actual directory path where you want to create the directory and save the output files.
In this example, the playbook performs the following tasks:
Creates the directory using the
file
module withstate: directory
. Adjust thepath
parameter to the desired directory path.Saves the output file
output1.txt
in the created directory using thecopy
module. Adjust thecontent
anddest
parameters as needed.Saves another output file
output2.txt
in the same directory using thecopy
module. Adjust thecontent
anddest
parameters accordingly.
Execute the playbook using the ansible-playbook
command:
ansible-playbook create_directory.yml
The playbook will create the directory and save the output files in that directory.