Skip to content
This repository was archived by the owner on Mar 23, 2019. It is now read-only.
This repository was archived by the owner on Mar 23, 2019. It is now read-only.

jinja env lookup within container.yml does not find environment variables #703

@shalomb

Description

@shalomb
ISSUE TYPE
  • Bug Report
container.yml
---

version: "2"

settings:
  conductor:
    base: debian:latest

services:
  web:
    from: busybox:latest
    ports:
      - "8080:80"
    environment:
      - 'VARFOO={{ lookup("env", "VARFOO") }}'

    command: ['/bin/sh', '-lc', 'while :; do sleep 10; { date; env; } >> /tmp/container.log; done']

registries: {}

OS / ENVIRONMENT
Ansible Container, version 0.9.2rc0
Linux, iris, 4.9.0-3-amd64, #1 SMP Debian 4.9.30-2+deb9u3 (2017-08-06), x86_64
2.7.13 (default, Jan 19 2017, 14:48:08)
[GCC 6.3.0 20170118] /usr/bin/python
{                                                     
  "ContainersPaused": 0,    
  "Labels": null,
  "CgroupDriver": "cgroupfs",
  "ContainersRunning": 1,     
  "ContainerdCommit": {                   
    "Expected": "9048e5e50717ea4497b757314bad98ea3763c145",
    "ID": "9048e5e50717ea4497b757314bad98ea3763c145"
  },
  "InitBinary": "docker-init",
  "NGoroutines": 29,
  "Swarm": {
    "ControlAvailable": false,
    "NodeID": "",
    "Error": "",
    "RemoteManagers": null,
    "LocalNodeState": "inactive",
    "NodeAddr": ""
  },
  "LoggingDriver": "json-file",
  "OSType": "linux",
  "HttpProxy": "",
  "Runtimes": {
    "runc": {
      "path": "docker-runc"
    }
  },
  "DriverStatus": [
    [
      "Pool Name",
      "docker-254:3-33606240-pool"
SUMMARY

Our on-premise GitLab CI jobs set environment variables that I would like to use within container.yml and https://docs.ansible.com/ansible-container/container_yml/template.html#passing-environment-variables notes that

In the case of the build command, for example, template rendering happens before any containers are started, and it occurs outside of the Ansible Build Container.
STEPS TO REPRODUCE
export VARFOO='42'
ansible-container --devel build
ansible-container --devel run --production
EXPECTED RESULTS

I would have expected VARFOO to be looked up by lookup("env", "VARFOO") and for the environment variable to be set in the container like so.

docker exec -it simplebusybox_web_1 grep VARFOO /tmp/container.log | tail -n 1
VARFOO=42
ACTUAL RESULTS

VARFOO happens to be empty in this case

docker exec -it simplebusybox_web_1 grep VARFOO /tmp/container.log | tail -n 1
VARFOO=

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions