directoryfilesystemsansible

How to create a directory using Ansible


How do you create a directory www at /srv on a Debian-based system using an Ansible playbook?


Solution

  • You want the ansible.builtin.file module. To create a directory, you need to specify the option state: directory:

    - name: Creates directory
      ansible.builtin.file:
        path: /src/www
        state: directory
    

    You can see other options at https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html