Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't the Ansible copy module copy this dir?

This should be easy, but I've been trying for an hour. My code gets Ansible to copy .vimrc to each host, but .vim is silently ignored.

---
- name: vim pkg
  apt: pkg=vim state=installed

- name: vim dirs
  file: path=/home/jefdaj/.vim state=directory
  file: path=/root/.vim        state=directory

- name: vim files

  # these work
  copy: src=vim/vimrc dest=/home/jefdaj/.vimrc force=yes
  copy: src=vim/vimrc dest=/root/.vimrc        force=yes

  # but these don't
  copy: src=vim/bundle dest=/home/jefdaj/.vim/bundle force=yes recurse=yes
  copy: src=vim/bundle dest=/root/.vim/bundle        force=yes recurse=yes

What's up with that? I've tried lots variations on the paths. It happens in ansible 1.5.5 on Debian, and also on the current git version.

EDIT: Now it tries to copy, but always fails while creating one of the many dirs with an error like OSError: [Errno 2] No such file or directory: '/root/.vim/bundle/bundle/vim-easymotion/autoload/vital/Over'

like image 251
jefdaj Avatar asked May 21 '14 22:05

jefdaj


2 Answers

Not sure why copy fails, but the solution was to use synchronize instead. This works:

- name: vim files
  synchronize:
    src=/absolute/repo/path/roles/common/files/{{ item.src }}
    dest={{ item.dst }}
  with_items:
    - {src: vim/bundle, dst: /home/jefdaj/.vim  }
    - {src: vim/vimrc , dst: /home/jefdaj/.vimrc}
    - {src: vim/bundle, dst: /root/.vim         }
    - {src: vim/vimrc , dst: /root/.vimrc       }

- name: vim permissions
  file: path={{ item.pth }} owner={{ item.own }} group={{ item.grp }} recurse=yes
  with_items:
    - {pth: /root/.vim         , own: root  , grp: root  }
    - {pth: /root/.vimrc       , own: root  , grp: root  }
    - {pth: /home/jefdaj/.vim  , own: jefdaj, grp: jefdaj}
    - {pth: /home/jefdaj/.vimrc, own: jefdaj, grp: jefdaj}

I had to hardcode the base path because it doesn't seem to handle relative ones properly.

like image 160
jefdaj Avatar answered Nov 01 '22 03:11

jefdaj


The problem with your file and copy tasks is that there are multiple actions in a task. An Ansible task can have only one action.

Change your play as follows and it should work:

---
- name: vim pkg
  apt: pkg=vim state=installed

- name: vim dir for jefdaj
  file: path=/home/jefdaj/.vim state=directory

- name: vim dir for root
  file: path=/root/.vim        state=directory

...

The same applies to "vim files" tasks: split them into four tasks.

like image 26
Pasi H Avatar answered Nov 01 '22 02:11

Pasi H