Ansible Install & Configure FTP Server on Linux Playbook

514 views Asked by At

I am trying to install and configure a FTP server using Ansible. I an running into syntax error. Can you please tell me correct syntax? I am not sure if it is a problem with looping through the list. The error message is not very helpful. It is saying that there is a problem with the first item in the list. Thanks.

---
- name: Deploy VSFTP and Web Server
  hosts: ftpservers #Group name of the server going to host FTP service
  tasks:
  - block:
    - name: Install FTP package on RHEL
      yum:
        name: vsftpd
        state: present
  - block:
    - name: Modify FTP configuation
      lineinfile:
        dest: /etc/vsftpd/vsftpd.conf
        backup: yes
        backrefs: yes
        state: present
        regexp: "{{ item.regexp }}"
        line: "{{ item.line }}"
      with_items:
        - { regexp: anonymous_enable=NO, line: anonymous_enable=YES }
        - { regexp: anon_upload_enable, line: anon_upload_enable=YES }
        - { regexp: anon_mkdir_write_enable, line: anon_mkdir_write_enable=YES }
  - block:
    - name: Start FTP service
      service: name=vsftpd state=restarted enabled=yes
1

There are 1 answers

0
Amar On

I was able to solve my problem using this online YAML linter. I am posting the working code below.

---
- name: Deploy VSFTP and Web Server
  hosts: linuxftp
  become: true
  tasks:
    - block:
        - name: Install FTP package on RHEL
          ansible.builtin.package:
            name: vsftpd
            state: present
    - block:
        - name: Modify FTP configuation
          lineinfile:
            dest: /etc/vsftpd/vsftpd.conf
            backup: yes
            state: present
            regexp: "{{ item.regexp }}"
            line: "{{ item.line }}"
          with_items:
            - regexp: anonymous_enable=NO
              line: anonymous_enable=YES
            - regexp: anon_upload_enable
              line: anon_upload_enable=YES
            - regexp: anon_mkdir_write_enable
              line: anon_mkdir_write_enable=YES
            - regexp: listen=NO
              line: listen=YES
            - regexp: listen_ipv6=YES
              line: listen_ipv6=NO
            - regexp: local_enable=NO
              line: local_enable=YES
            - regexp: pam_service_name
              line: pam_service_name=vsftpd
            - regexp: write_enable=NO
              line: write_enable=YES
            - regexp: anon_root
              line: anon_root=/var/ftp
            - regexp: no_anon_password=NO
              line: no_anon_password=YES
    - block:
        - name: Start FTP service
          become: yes
          service: name=vsftpd state=restarted enabled=yes