Skip to content

Commit

Permalink
Merge pull request #1 from indigo-dc/devel
Browse files Browse the repository at this point in the history
Implement some improvements
  • Loading branch information
maricaantonacci authored Dec 3, 2021
2 parents d3c75ac + ef2c55f commit 9194aa1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 51 deletions.
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
Role ansible-role-docker_run
Role docker_run
=========

The role starts a docker run from images and parameters provided.
The role starts a docker container from the specified image and parameters.

Requirements
------------

Docker need to be available in the system. Role suitable for Ubuntu Xsenial (16.04).
Docker needs to be available in the system. This requirement is managed via indigo-dc.docker dependency)

Role Variables
--------------

```
appname: name of the container
image: image to be used, default ubuntu
tag: tag for the image to be used, default latest
ports: as from the docker syntax: 8080 or 8080:80, default "80", mandatory
command: command to be executed, can be left blank
```

- `docker_run_appname`: name of the container
- `docker_run_image`: image to be used. Default: ubuntu
- `docker_run_tag`: tag for the image to be used. Default: latest
- `docker_run_env_variables`: list of environment variables (key/value pair) - see below. Default: []
- `docker_run_ports`: list of ports to publish from the container to the host. Use the docker CLI syntax, e.g. [ "8080" ] or [ "8080:80" ]. Default: []
- `docker_run_command`: command to be executed, can be left blank


Environment variables
--------------
Environment variables are supported and passed via TOSCA Template as a list on the form FOO=BAR
Environment variables are supported and passed as a list of key/value pairs.
Varaible(s) are copied down into a file .env that is used to start the container.
```
env_file: /opt/{{ appname }}/.env --> path to file containig a list of environment variables on the form FOO=BAR
env_file: /opt/{{ docker_run_appname }}/.env --> path to file containig a list of environment variables in the form FOO=BAR
```

Dependencies
------------

None
- indigo-dc.docker

Example Playbook
----------------
Expand All @@ -40,11 +41,11 @@ Example Playbook
remote_user: root
roles:
- role: ansible-role-docker_run
appname: container
image: ubuntu
tag: latest
ports: "80"
command: "printenv"
docker_run_appname: nginx
docker_run_image: nginx
docker_run_tag: latest
docker_run_ports: [ "8080:80" ]
docker_run_command: ""
```


Expand Down
11 changes: 6 additions & 5 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
# defaults file for ansible-role-docker_run
appname: ubuntu
image: ubuntu
tag: latest
ports: "80"
command: ""
docker_run_appname: ubuntu
docker_run_image: ubuntu
docker_run_tag: latest
docker_run_env_variables: []
docker_run_ports: []
docker_run_command: ""
38 changes: 10 additions & 28 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,32 @@
---

# - name: Install pip
# apt:
# name: python-pip
# state: present
#
# - name: Install docker
# pip:
# name: docker
#
# - name: Ensure docker service is enabled
# service:
# name: docker
# state: started
# enabled: yes
#
- name: "create directory path to store the configuration files"
file:
path: "/opt/{{ appname }}"
path: "/opt/{{ docker_run_appname }}"
state: directory
mode: 0755

- name: Touch the configuration file
file:
path: /opt/{{ appname }}/.env
path: /opt/{{ docker_run_appname }}/.env
state: touch
mode: u=rw,g=r,o=r

- name: debug
debug:
var: environment_variables

- name: Set environment variables
lineinfile:
path: /opt/{{ appname }}/.env
path: /opt/{{ docker_run_appname }}/.env
line: "{{ item.key }}={{ item.value }}"
create: yes
with_dict: "{{ environment_variables }}"
with_dict: "{{ docker_run_env_variables }}"


- name: Running the container
docker_container:
name: "{{ appname }}"
image: "{{ image }}:{{ tag }}"
env_file: /opt/{{ appname }}/.env
command: "{{ command }}"
ports:
- "{{ ports }}"
name: "{{ docker_run_appname }}"
image: "{{ docker_run_image }}:{{ docker_run_tag }}"
env_file: /opt/{{ docker_run_appname }}/.env
command: "{{ docker_run_command }}"
ports: "{{ docker_run_ports }}"
detach: True
state: started

0 comments on commit 9194aa1

Please sign in to comment.