Deploy *.war to wildfly with ansible

There is a lot to say here :smiley:

I can´t be root

That’s an important distinction here, though you might not need it if your CI user is in local ‘docker’ group on remote node and doesn’t need to write on root-owned parts of your filesystem.

I’m thinking you might as well copy your wars directly in your Wildfly container and avoid using volumes / mounts altogether.

From your screenshot:

  • You use ‘command’ module to execute ansible locally on what seems to be your Wildfy remote host to copy local files to your Wildfly server. Please don’t do that :slight_smile:. I don’t know where you run your command from but it’s becoming a bit confusing, and will surely also induce weird behaviors, which will be harder to troubleshoot.
    I’m guessing you do that because you don’t have your wars files locally, though in the end the command will be run from your Jenkins pipeline, so on the same node, in the same workspace.
    That’s still not the way to go, but it could be more efficient this way: ansible -i /etc/ansible/hosts.yml wildfly -m command -a 'ansible -c local localhost -m copy -a...', or better: ansible -i /etc/ansible/hosts.yml wildfly -m command -a 'mv <srcFiles> <dstFolder>/', or use a playbook like this instead:

    - hosts: wildfly
      gather_facts: false
      tasks:
        - name: Synchronize folders locally
          ansible.posix.synchronize:
            src: <srcPathOnRemoteHost>
            dest: <destPathOnRemoteHost>
          delegate_to: wildfly
    
    # Then perhaps delete files in src directory; synchronize module might even have a paramater for that, I don't know
    

    And run it with: ansible-playbook -i /etc/ansible/hosts.yml -l wildfly <yourPlaybookPath>

  • I don’t understand how you’re running a second command without a commands separator or operator (still in your first ansible -m command command). And I realize now there is a second task I haven’t put in my playbook example above. Oh well…

  • I see you can run sudo docker cp so it seems you have sudo permissions to run docker or full root access through sudo, though you said you didn’t. No biggie, just wondering.

  • Error message about ssh password is misleading; I think you just need to either connect through ssh manually to this host prior, add his hostkeys manually or disable hostkeys checking in Ansible config altogether (not best practice, but hey !). See a post I made on another thread earlier tonight on this: Headless Ansible - #5 by ptn

I will have to study a lot docker, yaml, ansible, scripts, arameo language, german language, chinese language and UFO language… hahahahahaha.

I love your quirkiness haha !

It’s getting late here (and I’m getting really hungry), so please allow me one day or two (or more depending on what’s on my plate) and I’ll get back to you with an example playbook you could adapt to your needs.

Have a nice evening !