简体   繁体   中英

Ansible can't build Grails war on a vagrant machine

My first question to the SO community :)

I am using Ansible to provision a Vagrant machine. The task is to deploy the grails war file onto tomcat7.

When I run the task to build the war file I get this error:

TASK [Build application] ******************************************************* fatal: [vagrant]: FAILED! => {"changed": true, "cmd": ["sh", "/home/vagrant/src/grailsw", "war"], "delta": "0:00:00.110227", "end": "2017-03-23 12:12:07.728096", "failed": true, "rc": 1, "start": "2017-03-23 12:12:07.617869", "stderr": "Error: Could not find or load main class org.grails.wrapper.GrailsWrapper", "stdout": "", "stdout_lines": [], "warnings": []} to retry, use: --limit @/home/user/work/scratch/vagrant/petclinic_ansible/playbook.retry

If I vagrant ssh into the machine and run ./gradlew war then the war file is created But i can't create the war file using ansible

Here is my vagrant file:

Vagrant.configure("2") do |config|

  config.vm.define "vagrant" do |config|
      config.vm.box = "bento/ubuntu-16.04"
      config.vm.network :private_network, ip: "192.168.10.10"

      config.vm.provision "ansible" do  |ansible|
          ansible.playbook = "playbook.yml"
      end
  end

  config.vm.provider  "virtualbox" do  |vb|
      vb.memory = "1024"
      vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
  end
 end

And here is my playbook.yml

- hosts: all
become: true

  roles:
      - java
      - servers

tasks:
    - name: Make sure src directory doesn't exist
      file:
        path: /home/vagrant/src
        state: absent
        force: yes

    - name: Pull repository
      git:
        repo: https://github.com/Rcsuax/grails-petclinic.git
        dest: /home/vagrant/src
        version: master

    - name: Build application
      become: true
      command: ./home/vagrant/src/grailsw war

So I'm not sure why command: ./home/vagrant/src/grailsw war doesn't work but I replaced the command module with the shell module, and it now compiles. Hopefully this is useful for anyone else with a similar issue. Solution:

  - name: Build application
    become: true
    shell: ./grailsw war
    args:
      chdir: src/
      creates: target/petclinic-0.2.war
    environment:
        JAVA_HOME: /usr/lib/jvm/java-8-oracle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM