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.19k stars 392 forks source link

TypeError: ordereddict is not JSON serializable #961

Closed soroushatarod closed 6 years ago

soroushatarod commented 6 years ago
ISSUE TYPE
container.yml
version: "2"
settings:
  conductor:
    base: "ubuntu:xenial"
  project_name: "ansible-container-demo"

services:
  flask:
    from: "ubuntu:xenial"
    roles:

      - role: flask
    ports:
      - "5000"
    command: ["gunicorn", "--bind", "0.0.0.0:5000", "app:app", "--chdir", "/app"]

  nginx:
    from: "ubuntu:xenial"
    roles:
      - role: "nginx"
        nginx_proxy_host: "flask"
        nginx_proxy_port: 5000
        nginx_listen_port: 8080
    ports:
      - "8080:8080"
    command: ["nginx", "-c", "/etc/nginx/nginx_ansible.conf", "-g", "daemon off;"]
OS / ENVIRONMENT
Ansible Container, version 0.9.2
Linux, ip-172-31-28-191.eu-west-2.compute.internal, 4.14.47-64.38.amzn2.x86_64, #1 SMP Mon Jun 18 22:33:07 UTC 2018, x86_64
2.7.14 (default, Jun 19 2018, 17:14:23)
[GCC 7.3.1 20180303 (Red Hat 7.3.1-5)] /usr/bin/python2
{
  "ContainersPaused": 0,
  "Labels": [],
  "CgroupDriver": "cgroupfs",
  "ContainersRunning": 0,
  "ContainerdCommit": {
    "Expected": "773c489c9c1b21a6d78b5c538cd395416ec50f88",
    "ID": "773c489c9c1b21a6d78b5c538cd395416ec50f88"
  },
  "InitBinary": "docker-init",
  "NGoroutines": 34,
  "Swarm": {
    "ControlAvailable": false,
    "NodeID": "",
    "Error": "",
    "RemoteManagers": null,
    "LocalNodeState": "inactive",
    "NodeAddr": ""
  },
  "LoggingDriver": "json-file",
  "OSType": "linux",
  "HttpProxy": "",
  "Runtimes": {
    "runc": {
      "path": "docker-runc"
    }
  },
  "DriverStatus": [
    [
      "Backing Filesystem",
      "xfs"
    ],
    [
      "Supports d_type",
      "true"
    ],
    [
      "Native Overlay Diff",
      "true"
    ]
  ],
  "OperatingSystem": "Amazon Linux 2",
  "Containers": 0,
  "HttpsProxy": "",
  "BridgeNfIp6tables": true,
  "MemTotal": 1035329536,
  "SecurityOptions": [
    "name=seccomp,profile=default"
  ],
  "Driver": "overlay2",
  "IndexServerAddress": "https://index.docker.io/v1/",
  "ClusterStore": "",
  "InitCommit": {
    "Expected": "949e6fa",
    "ID": "949e6fa"
  },
  "GenericResources": null,
  "Isolation": "",
  "SystemStatus": null,
  "OomKillDisable": true,
  "ClusterAdvertise": "",
  "SystemTime": "2018-08-13T22:40:31.714366801Z",
  "Name": "ip-172-31-28-191.eu-west-2.compute.internal",
  "CPUSet": true,
  "RegistryConfig": {
    "AllowNondistributableArtifactsCIDRs": [],
    "Mirrors": [],
    "IndexConfigs": {
      "docker.io": {
        "Official": true,
        "Name": "docker.io",
        "Secure": true,
        "Mirrors": []
      }
    },
    "AllowNondistributableArtifactsHostnames": [],
    "InsecureRegistryCIDRs": [
      "127.0.0.0/8"
    ]
  },
  "DefaultRuntime": "runc",
  "ContainersStopped": 0,
  "NCPU": 1,
  "NFd": 20,
  "Architecture": "x86_64",
  "KernelMemory": true,
  "CpuCfsQuota": true,
  "Debug": false,
  "ID": "OJRJ:3OLO:NMWZ:RXQP:DH3L:XPC4:34ZX:JUMJ:NYBJ:GYBE:PWOC:B7ZD",
  "IPv4Forwarding": true,
  "KernelVersion": "4.14.47-64.38.amzn2.x86_64",
  "BridgeNfIptables": true,
  "NoProxy": "",
  "LiveRestoreEnabled": false,
  "ServerVersion": "18.03.1-ce",
  "CpuCfsPeriod": true,
  "ExperimentalBuild": false,
  "MemoryLimit": true,
  "SwapLimit": true,
  "Plugins": {
    "Volume": [
      "local"
    ],
    "Network": [
      "bridge",
      "host",
      "macvlan",
      "null",
      "overlay"
    ],
    "Authorization": null,
    "Log": [
      "awslogs",
      "fluentd",
      "gcplogs",
      "gelf",
      "journald",
      "json-file",
      "logentries",
      "splunk",
      "syslog"
    ]
  },
  "Images": 5,
  "DockerRootDir": "/var/lib/docker",
  "NEventsListener": 0,
  "CPUShares": true,
  "RuncCommit": {
    "Expected": "4fc53a81fb7c994640722ac585fa9ca548971871",
    "ID": "4fc53a81fb7c994640722ac585fa9ca548971871"
  }
}
{
  "KernelVersion": "4.14.47-64.38.amzn2.x86_64",
  "Components": [
    {
      "Version": "18.03.1-ce",
      "Name": "Engine",
      "Details": {
        "KernelVersion": "4.14.47-64.38.amzn2.x86_64",
        "Os": "linux",
        "BuildTime": "2018-07-25T00:51:07.000000000+00:00",
        "ApiVersion": "1.37",
        "MinAPIVersion": "1.12",
        "GitCommit": "7390fc6/18.03.1-ce",
        "Arch": "amd64",
        "Experimental": "false",
        "GoVersion": "go1.9.6"
      }
    }
  ],
  "Arch": "amd64",
  "BuildTime": "2018-07-25T00:51:07.000000000+00:00",
  "ApiVersion": "1.37",
  "Platform": {
    "Name": ""
  },
  "Version": "18.03.1-ce",
  "MinAPIVersion": "1.12",
  "GitCommit": "7390fc6/18.03.1-ce",
  "Os": "linux",
  "GoVersion": "go1.9.6"
}
SUMMARY

Try to build a simple docker container image using Ansible. It was initially throwing the " 'tuple' object not found " which I then run

 pip install -U docker==2.7.0

to make it pass that exception. However, its now displaying TYperError: ordereddict.

STEPS TO REPRODUCE
ansible-container --debug build
EXPECTED RESULTS

I expected it to build successfully.

ACTUAL RESULTS
age caller_line=1038
Step 1/5 : FROM ansible/container-conductor-ubuntu-xenial:0.9.2

 ---> 35cf9762959e
Step 2/5 : VOLUME /usr

 ---> Using cache
 ---> 5327e3fd41ec
Step 3/5 : VOLUME /lib

 ---> Using cache
 ---> ac8277d328de
Step 4/5 : COPY /build-src /_ansible/build

 ---> Using cache
 ---> fc5ca923489b
Step 5/5 : RUN ( test -f /_ansible/build/ansible-requirements.txt && pip install --no-cache-dir -r /_ansible/build/ansible-requirements.txt || true ) &&     ( test -f /_ansible/build/requirements.yml && ansible-galaxy install -p /etc/ansible/roles -r /_ansible/build/requirements.yml || true ) &&     ( test -f /_ansible/build/ansible.cfg && cp /_ansible/build/ansible.cfg /etc/ansible/ansible.cfg || true)

 ---> Using cache
 ---> cf243a2d77d3
{"aux": {"ID": "sha256:cf243a2d77d30210125e28ecf71813c7dbf2f1a9e5fd1a77448df975e82c0462"}}
Successfully built cf243a2d77d3
Successfully tagged ansible-container-demo-conductor:latest
2018-08-13T22:43:28.370354 Cleaning up temporary directory [container.utils.temp] caller_file=/usr/lib/python2.7/site-packages/container/utils/temp.py caller_func=__exit__ caller_line=22 path=/tmp/tmp7Gc_4H
2018-08-13T22:43:28.371881 Config settings                [container.core] caller_file=/usr/lib/python2.7/site-packages/container/core.py caller_func=hostcmd_build caller_line=191 conf=<class 'container.docker.config.AnsibleContainerConfig'> config=<container.docker.config.AnsibleContainerConfig object at 0x7f8d2c1990d0> rawsettings=ordereddict([('conductor', ordereddict([('base', 'ubuntu:xenial')])), ('project_name', 'ansible-container-demo'), ('pwd', '/home/ec2-user/ansible')]) settings=ordereddict([('conductor', ordereddict([('base', 'ubuntu:xenial')])), ('project_name', 'ansible-container-demo'), ('pwd', '/home/ec2-user/ansible')])
2018-08-13T22:43:28.372951 Call: Engine.run_conductor     [container.docker.engine] args=('build', {'services': ordereddict([('flask', ordereddict([('from', 'ubuntu:xenial'), ('roles', [ordereddict([('role', 'flask')])]), ('ports', ['5000']), ('command', ['gunicorn', '--bind', '0.0.0.0:5000', 'app:app', '--chdir', '/app'])])), ('nginx', ordereddict([('from', 'ubuntu:xenial'), ('roles', [ordereddict([('role', 'nginx'), ('nginx_proxy_host', 'flask'), ('nginx_proxy_port', 5000), ('nginx_listen_port', 8080)])]), ('ports', ['8080:8080']), ('command', ['nginx', '-c', '/etc/nginx/nginx_ansible.conf', '-g', 'daemon off;'])]))]), 'version': '2', 'defaults': ordereddict([]), 'settings': ordereddict([('conductor', ordereddict([('base', 'ubuntu:xenial')])), ('project_name', 'ansible-container-demo'), ('pwd', '/home/ec2-user/ansible')])}, '/home/ec2-user/ansible', {'with_volumes': [], 'config_vars': ordereddict([]), 'conductor_cache': True, 'local_python': False, 'with_variables': [], 'selinux': True, 'purge_last': True, 'cache': True, 'volume_driver': None, 'devel': False, 'src_mount_path': None, 'roles_path': [], 'subcommand': 'build', 'ansible_options': u'', 'flatten': False, 'container_cache': True, 'debug': True, 'services_to_build': None, 'save_conductor_container': False}) caller_file=/usr/lib/python2.7/site-packages/container/docker/engine.py caller_func=Engine.run_conductor caller_line=23 kwargs={}
2018-08-13T22:43:28.378005 Unknown exception ordereddict([('from', 'ubuntu:xenial'), ('roles', [ordereddict([('role', 'flask')])]), ('ports', ['5000']), ('command', ['gunicorn', '--bind', '0.0.0.0:5000', 'app:app', '--chdir', '/app'])]) is not JSON serializable [container.cli] caller_file=/usr/lib/python2.7/site-packages/structlog/stdlib.py caller_func=exception caller_line=95
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/container/cli.py", line 299, in __call__
    getattr(core, u'hostcmd_{}'.format(args.subcommand))(**vars(args))
  File "/usr/lib/python2.7/site-packages/container/__init__.py", line 28, in __wrapped__
    return fn(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/container/core.py", line 201, in hostcmd_build
    'build', dict(config), base_path, kwargs, save_container=save_container)
  File "/usr/lib/python2.7/site-packages/container/docker/engine.py", line 454, in await_conductor_command
    conductor_id = self.run_conductor(command, config, base_path, params)
  File "/usr/lib/python2.7/site-packages/container/docker/engine.py", line 105, in __wrapped__
    return fn(self, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/container/__init__.py", line 28, in __wrapped__
    return fn(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/container/docker/engine.py", line 408, in run_conductor
    serialized_config = base64.b64encode(json.dumps(ordereddict_to_list(config)).encode("utf-8")).decode()
  File "/usr/lib64/python2.7/json/__init__.py", line 244, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib64/python2.7/json/encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib64/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib64/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: ordereddict([('from', 'ubuntu:xenial'), ('roles', [ordereddict([('role', 'flask')])]), ('ports', ['5000']), ('command', ['gunicorn', '--bind', '0.0.0.0:5000', 'app:app', '--chdir', '/app'])]) is not JSON serializable
tzok commented 6 years ago

Please take a look at #958 and my PR #959 . These concern the same error you mention and the PR contains a fix.

Briefly: clone ansible-container, change requirements.txt and conductor-requirements.txt to have ruamel.yaml at most in 0.15.51 version.

soroushatarod commented 6 years ago

thanks! It's fixed. I think the https://pypi.org/project/ansible-container/0.9.2/#files needs to be updated to include the updated build.