How to docker exec in ansible?

1,117 views
Skip to first unread message

Joaquin Menchaca

unread,
Sep 28, 2016, 10:27:45 PM9/28/16
to Ansible Project
I would like to build a container then run some commands on it... 

  - name: Log into DockerHub
    docker_login:
      username: "{{docker_hub_username}}"
      password: "{{docker_hub_password}}"
      email: "{{docker_hub_email}}"
  - name: Build Foo Container
    docker:
      name: foo
      image: gobaltoops/foo:{{ git_hash_short }}
      state: reloaded
      pull: always
      command: bash "{{ app_root }}"/"{{ config_path }}"/"{{ app_env }}"/wrapper.sh
      volumes:
           - "{{ foo_base_dir }}/templates:/templates"
           - "{{ foo_base_dir}}/logs:{{ app_root }}/logs"
           - "{{ foo_base_dir }}/target:{{ app_root }}/output"
      env:
          APP_ROOT: "{{ app_root }}"

I would then like to run after:

docker exec -t foo config arg1
docker exec -t foo migrate source
docker exec -t foo build $GIT_HASH_SHORT

I tried this, but it didn't work:

- hosts: foo
  connection: docker
  tasks:
    - command: config arg1
    - command: migrate source
    - command: build {{ git_hash_short }}


Reply all
Reply to author
Forward
0 new messages