wrk 2024-12-27 08-34-47
name: Mount CIFS Share using systemd hosts: all become: true vars: cifs_share: "//10.12.69.11/tst" mount_point: "/mnt/shara" username: "Ваше_имя_пользователя" password: "Ваш_пароль" credentials_file: "/root/.smbcredentials" tasks: - name: Install required packages ansible.builtin.package: name: - cifs-utils state: present - name: Create mount point directory ansible.builtin.file: path: "{{ mount_point }}" state: directory mode: '0755' owner: root group: root - name: Create credentials file if it does not exist ansible.builtin.copy: dest: "{{ credentials_file }}" content: | username={{ username }} password={{ password }} mode: '0600' owner: root group: root force: false - name: Create systemd mount unit file ansible.builtin.copy: dest: "/etc/systemd/system/mnt-shara.mount" content: | [Unit] Description=Mount CIFS Share to {{ mount_point }} Requires=network-online.target After=network-online.target [Mount] What={{ cifs_share }} Where={{ mount_point }} Type=cifs Options=credentials={{ credentials_file }},file_mode=0666,dir_mode=0777 [Install] WantedBy=multi-user.target - name: Create systemd automount unit file ansible.builtin.copy: dest: "/etc/systemd/system/mnt-shara.automount" content: | [Unit] Description=Automount for CIFS Share to {{ mount_point }} Requires=network-online.target [Automount] Where={{ mount_point }} [Install] WantedBy=remote-fs.target - name: Reload systemd daemon ansible.builtin.systemd: daemon_reload: true - name: Enable and start automount service ansible.builtin.systemd: name: mnt-shara.automount enabled: true state: started