ansible / ansible-container

DEPRECATED -- Ansible Container was a tool to build Docker images and orchestrate containers using only Ansible playbooks.
GNU Lesser General Public License v3.0
2.18k stars 392 forks source link

Wrong templating behavior with pseudo boolean values #666

Open jbrinksmeier opened 7 years ago

jbrinksmeier commented 7 years ago
ISSUE TYPE
container.yml
version: "2"
settings:
  conductor_base: centos:7

services:
  test:
    from: centos:7
    command: ['/usr/bin/tail', '-f', '/dev/null']
    roles:
      - role: some-template
        file_path: '/root/my-template.conf'
        my_var: 'on'
OS / ENVIRONMENT
Ansible Container, version 0.9.1
Linux, jojo-ThinkPad-T530, 4.4.0-83-generic, #106-Ubuntu SMP Mon Jun 26 17:54:43 UTC 2017, x86_64
2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] /usr/bin/python
{
  "ContainersPaused": 0, 
  "Labels": null, 
  "CgroupDriver": "cgroupfs", 
  "ContainersRunning": 1, 
  "ContainerdCommit": {
    "Expected": "4ab9917febca54791c5f071a9d1f404867857fcc", 
    "ID": "4ab9917febca54791c5f071a9d1f404867857fcc"
  }, 
  "InitBinary": "docker-init", 
  "NGoroutines": 29, 
  "Swarm": {
    "Managers": 0, 
    "ControlAvailable": false, 
    "NodeID": "", 
    "Cluster": {
      "Spec": {
        "TaskDefaults": {}, 
        "Orchestration": {}, 
        "EncryptionConfig": {
          "AutoLockManagers": false
        }, 
        "Raft": {
          "HeartbeatTick": 0, 
          "ElectionTick": 0
        }, 
        "CAConfig": {}, 
        "Dispatcher": {}
      }, 
      "Version": {}, 
      "ID": "", 
      "CreatedAt": "0001-01-01T00:00:00Z", 
      "UpdatedAt": "0001-01-01T00:00:00Z"
    }, 
    "Nodes": 0, 
    "Error": "", 
    "RemoteManagers": null, 
    "LocalNodeState": "inactive", 
    "NodeAddr": ""
  }, 
  "LoggingDriver": "json-file", 
  "OSType": "linux", 
  "HttpProxy": "", 
  "Runtimes": {
    "runc": {
      "path": "docker-runc"
    }
  }, 
  "DriverStatus": [
    [
      "Root Dir", 
      "/var/lib/docker/aufs"
    ], 
    [
      "Backing Filesystem", 
      "extfs"
    ], 
    [
      "Dirs", 
      "226"
    ], 
    [
      "Dirperm1 Supported", 
      "true"
    ]
  ], 
  "OperatingSystem": "Ubuntu 16.04.2 LTS", 
  "Containers": 11, 
  "HttpsProxy": "", 
  "BridgeNfIp6tables": true, 
  "MemTotal": 16513073152, 
  "SecurityOptions": [
    "name=apparmor", 
    "name=seccomp,profile=default"
  ], 
  "Driver": "aufs", 
  "IndexServerAddress": "https://index.docker.io/v1/", 
  "ClusterStore": "", 
  "InitCommit": {
    "Expected": "949e6fa", 
    "ID": "949e6fa"
  }, 
  "Isolation": "", 
  "SystemStatus": null, 
  "OomKillDisable": true, 
  "ClusterAdvertise": "", 
  "SystemTime": "2017-07-25T17:17:41.126206236+02:00", 
  "Name": "jojo-ThinkPad-T530", 
  "CPUSet": true, 
  "RegistryConfig": {
    "InsecureRegistryCIDRs": [
      "127.0.0.0/8"
    ], 
    "IndexConfigs": {
      "docker.io": {
        "Official": true, 
        "Name": "docker.io", 
        "Secure": true, 
        "Mirrors": null
      }
    }, 
    "Mirrors": []
  }, 
  "DefaultRuntime": "runc", 
  "ContainersStopped": 10, 
  "NCPU": 8, 
  "NFd": 23, 
  "Architecture": "x86_64", 
  "KernelMemory": true, 
  "CpuCfsQuota": true, 
  "Debug": false, 
  "ID": "DZIR:Q5FC:P4K3:7V5P:HH3F:LFVZ:XHHS:6PFL:3KPX:WXZZ:BKNQ:NWT6", 
  "IPv4Forwarding": true, 
  "KernelVersion": "4.4.0-83-generic", 
  "BridgeNfIptables": true, 
  "NoProxy": "", 
  "LiveRestoreEnabled": false, 
  "ServerVersion": "17.03.2-ce", 
  "CpuCfsPeriod": true, 
  "ExperimentalBuild": false, 
  "MemoryLimit": true, 
  "SwapLimit": false, 
  "Plugins": {
    "Volume": [
      "local"
    ], 
    "Network": [
      "bridge", 
      "host", 
      "macvlan", 
      "null", 
      "overlay"
    ], 
    "Authorization": null
  }, 
  "Images": 233, 
  "DockerRootDir": "/var/lib/docker", 
  "NEventsListener": 0, 
  "CPUShares": true, 
  "RuncCommit": {
    "Expected": "54296cf40ad8143b62dbcaa1d90e520a2136ddfe", 
    "ID": "54296cf40ad8143b62dbcaa1d90e520a2136ddfe"
  }
}
{
  "KernelVersion": "4.4.0-83-generic", 
  "Arch": "amd64", 
  "BuildTime": "2017-06-27T03:35:14.394387481+00:00", 
  "ApiVersion": "1.27", 
  "Version": "17.03.2-ce", 
  "MinAPIVersion": "1.12", 
  "GitCommit": "f5ec1e2", 
  "Os": "linux", 
  "GoVersion": "go1.7.5"
}
SUMMARY

I want to fill values to a container's file. The values are on/off as strings and get parsed to True/False when running the template task.

STEPS TO REPRODUCE

I setup a minimum reproducible example here: https://github.com/jbrinksmeier/ac-template-bug

git clone git@github.com:jbrinksmeier/ac-template-bug.git

cd ac-template-bug

ansible-container build

ansible-container run

docker exec -it actemplatebug_test_1 cat /root/my-template.conf
EXPECTED RESULTS

Should echo on

ACTUAL RESULTS

Echos True

chouseknecht commented 7 years ago

@jbrinksmeier

Thanks for using Ansible Container, and for taking the time to share your feedback.

We use Templar from Ansible to apply templates, see config.py.

I believe, and I could be wrong, that the true and false string values defined in Ansible are defined here: https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/action/set_fact.py#L48 There are only 4 values: 'true', 'false', 'yes', 'no'.

If you're proposing a change, I would say that Ansible Container should adopt Ansible's behavior, and only support the same 4 values.

jbrinksmeier commented 7 years ago

actually, ansible 2.3 accepts string values, I may pass 'on' as well as 'true' and get the desired values in the resulting files. Maybe that changed in 2.4, don't know.

I think that we should at least be able to force a string value, using

my_var: !!str 'on'

for example as suggested here: https://github.com/ansible/ansible/issues/11905#issuecomment-287879064

sradco commented 5 years ago

I hit this issue as well. Ansible 2.7. my_var: on is converted during the playbook run to true.

When updated my_var: "on" variable is working as expected.