Search code examples
laraveldeploymentansiblesynchronize

ansible synchronize with excludes file role


Im creating an ansible role for deploying laravel5 project, now I do that with a "synchronize" (rsync)

I have my excludes file for the rsync, and the files structured like this:

the: "deploy-laravel5" role:

 files
   excludes
 tasks
   main.yml

now here is the tasks in main.yml:

- name: deploy laravel projects
  synchronize:
    src: "{{item.src}}"
    dest: "{{item.dest}}"
    rsync_opts:
      - "--exclude-from=excludes"
  with_items: "{{projects}}"

some playbook:

---

- hosts: php
  gather_facts: no

  vars:
  projects:
    - {src: "../../twitter/", dest: "/web/boom/", envFile: "twitter.env"}


  roles:
    - deploy-laravel5

now when I run that, ansible says it can't find the "excludes" file

 msg: rsync: failed to open exclude file excludes: No such file or directory (2)

I tried many different paths but nothing, any ideas how to point to the excludes file?


Solution

  • After I browsed the web and the docs quite extensively, I found that you can't define othe files in the "role" only files for templating or copying.

    But you can define the file inside a playbook, so now the file structure is like this:

     roles/
        deploy/  (NOT "deploy-laravel5" as before)
    
     playbooks/
         deploy-laravel5/
            excludes-file
            deploy-playbook.yml
    

    and the playbook looks quite the same:

    ---
    
    - hosts: php
      gather_facts: no
    
      vars:
        projects:
          - {src: "../../twitter/",
             dest: "/web/boom/", 
             excludes-file: "path/to/excludes/file",
             envFile: "twitter.env"}
    
    
      roles:
        - deploy