Run Command Inside of Docker Container Using Ansible

前端 未结 5 721
情话喂你
情话喂你 2020-12-07 16:48

what I\'m trying to accomplish is to run commands inside of a Docker container that has already been created on a Digital Ocean Ubuntu/Docker Droplet using Ansible.

5条回答
  •  再見小時候
    2020-12-07 17:19

    Update: there is a way to do this without using my module, see my other answer

    I wrote a simple module to run exec on a remote Docker host. I've submitted it to the ansible project, but you can easily add it to your own projects if you need to. The module is only 23 lines long, take it from my pull request and add it to your ./library directory, and then you can add a task in your playbook like so:

      - name: Run docker exec command
        docker_exec: 
          command: 
          docker_host: 
          name: 
        register: exec_output
    
      - name: Show exec output
        debug: msg="{{ exec_output.result }}"
    

提交回复
热议问题