Search code examples
bashshellansibledotfiles

Ansible install .dotfiles through Mathias installer


I am attempting to install the following files (mathiasbynens dotfiles) on a remote server using ansible.

Here is the roles/dotfiles/tasks/main.yml file contents:

---
 - name: Flag if dotfiles directory exists
   stat: path=/home/path/dotfiles
   register: dotfilesdirectory

 - name: Remove old dotfiles directory
   file: path=/home/path/dotfiles state=absent
   when: dotfilesdirectory.stat.exists
   register: olddirectoryremoved

 - name: Clone repository
   git: repo=https://github.com/mathiasbynens/dotfiles.git dest=/home/path/dotfiles
   when: not dotfilesdirectory.stat.exists or olddirectoryremoved|success
   register: repositorycloned

 - name: Instantiate dotfiles
   shell: source bootstrap.sh
   args:
    chdir: /home/path/dotfiles
    executable: /bin/bash
   when: repositorycloned|success

And I am getting the following output when running the playbook and using -vvvv:

fatal: [ready]: FAILED! => {"changed": true, "cmd": "bootstrap.sh", "delta": "0:00:00.003190", "end": "2016-04-17 12:25:22.480491", "failed": true, "invocation": {"module_args": {"_raw_params": "bootstrap.sh", "_uses_shell": true, "chdir": "/home/path/dotfiles", "creates": null, "executable": "/bin/bash", "removes": null, "warn": true}, "module_name": "command"}, "rc": 127, "start": "2016-04-17 12:25:22.477301", "stderr": "/bin/bash: bootstrap.sh: command not found", "stdout": "", "stdout_lines": [], "warnings": []}

Any idea what I am doing wrong? All I want to do is run the shell command of source with the argument of bootstrap.sh when I am in the dotfiles directory (i.e. source /home/path/dotfiles/bootstrap.sh). Everything I try either causes the script to hang when it gets to the last task on the list, or to error out with the error message above.

Thanks in advance!


Solution

  • Did you look at the content of bootstrap.sh? You don't want to source that file. You should execute it as follows

    ./bootstrap.sh --force

    Or if you really need to source it (probably not as an Ansible task) you could do exactly as it says in the README.md file

    set -- -f; source bootstrap.sh