0

I have a task in my Ansible Bitbucket role that simply starts two docker-compose.yml files. When executing this from Ansible it fails but when I execute the same command over ssh on the actual server it works just fine. I am currently executing my playbook as root, and when i manually execute docker-compose -f <path> up -d I am also root.

- name: Create and start services
    - name: docker compose up
      docker_compose:
        project_src: "{{ bitbucket__install_path }}"
        files: "{{ bitbucket__compose_files }}"
        state: present
      register: output

Ansible command:

ansible-playbook -i inventory/staging playbooks/bitbucket-server.yml -vvvv -kKu root --ask-vault-pass --start-at-task "Setup bitbucket"

Ansible sucessfully starts 2 out of 3 containers but the third crashes with the error:

Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/my_entrypoint.sh": permission denied: unknown Error: failed to start containers: nginx_bitbucket_1

My question is, why do Ansible receive an error when executing the above task while executing "docker-compose -f <path> up -d over ssh works just fine? What is the difference between the two cases?

Oskar Granlund
  • 399
  • 1
  • 4
  • 9
  • 1
    you hadn't provided enough info to answer. My wild guess may be that you run it from different user compare to your ssh session. – George Shuklin Oct 17 '21 at 10:20

1 Answers1

0

I found the solution for this problem. The problem is that the files field did not operate as I expected.

List of Compose file names relative to project_src. Overrides docker-compose.yml or docker-compose.yaml. Files are loaded and merged in the order given.

I thought the files parameter would execute docker-compose -f <path> up on each list element defined in the parameter.

I changed my code to use a loop rather than the files parameter

 - name: Create and start services                                                                                                                  
  docker_compose:
    project_src: "{{ bitbucket__install_path }}/{{ item }}"                                                                                        
    state: present                                                                                                                                                                                                                    
  loop:
    - nginx
    - bitbucket 

It finished sucessfully

Oskar Granlund
  • 399
  • 1
  • 4
  • 9