# Buggy code
def sign_in(self, timeout=60, safe=True, tries=1):
    """
    Send a sign in request to the master, sets the key information and
    returns a dict containing the master publish interface to bind to
    and the decrypted aes key for transport decryption.

    :param int timeout: Number of seconds to wait before timing out the sign-in request
    :param bool safe: If True, do not raise an exception on timeout. Retry instead.
    :param int tries: The number of times to try to authenticate before giving up.

    :raises SaltReqTimeoutError: If the sign-in request has timed out and :param safe: is not set

    :return: Return a string on failure indicating the reason for failure. On success, return a dictionary
    with the publication port and the shared AES key.

    """
    auth = {}

    auth_timeout = self.opts.get("auth_timeout", None)
    if auth_timeout is not None:
        timeout = auth_timeout
    auth_safemode = self.opts.get("auth_safemode", None)
    if auth_safemode is not None:
        safe = auth_safemode
    auth_tries = self.opts.get("auth_tries", None)
    if auth_tries is not None:
        tries = auth_tries

    m_pub_fn = os.path.join(self.opts["pki_dir"], self.mpub)

    auth["master_uri"] = self.opts["master_uri"]

    channel = salt.transport.client.ReqChannel.factory(self.opts, crypt="clear")

    sign_in_payload = self.minion_sign_in_payload()
    try:
        payload = channel.send(sign_in_payload, tries=tries, timeout=timeout)
    except SaltReqTimeoutError as e:
        if safe:
            log.warning("SaltReqTimeoutError: {0}".format(e))
            return "retry"
        raise SaltClientError("Attempt to authenticate with the salt master failed")

    if "load" in payload:
        if "ret" in payload["load"]:
            if not payload["load"]["ret"]:
                if self.opts["rejected_retry"]:
                    log.error(
                        "The Salt Master has rejected this minion's public "
                        "key.\nTo repair this issue, delete the public key "
                        "for this minion on the Salt Master.\nThe Salt "
                        "Minion will attempt to to re-authenicate."
                    )
                    return "retry"
                else:
                    log.critical(
                        "The Salt Master has rejected this minion's public "
                        "key!\nTo repair this issue, delete the public key "
                        "for this minion on the Salt Master and restart this "
                        "minion.\nOr restart the Salt Master in open mode to "
                        "clean out the keys. The Salt Minion will now exit."
                    )
                    sys.exit(salt.defaults.exitcodes.EX_OK)
            # has the master returned that its maxed out with minions?
            elif payload["load"]["ret"] == "full":
                return "full"
            else:
                log.error(
                    "The Salt Master has cached the public key for this "
                    "node. If this is the first time connecting to this master "
                    "then this key may need to be accepted using 'salt-key -a {0}' on "
                    "the salt master. This salt minion will wait for {1} seconds "
                    "before attempting to re-authenticate.".format(
                        self.opts["id"], self.opts["acceptance_wait_time"]
                    )
                )
                return "retry"
    auth["aes"] = self.verify_master(payload, master_pub="token" in sign_in_payload)
    if not auth["aes"]:
        log.critical(
            "The Salt Master server's public key did not authenticate!\n"
            "The master may need to be updated if it is a version of Salt "
            "lower than {0}, or\n"
            "If you are confident that you are connecting to a valid Salt "
            "Master, then remove the master public key and restart the "
            "Salt Minion.\nThe master public key can be found "
            "at:\n{1}".format(salt.version.__version__, m_pub_fn)
        )
        sys.exit(42)
    if self.opts.get("syndic_master", False):  # Is syndic
        syndic_finger = self.opts.get(
            "syndic_finger", self.opts.get("master_finger", False)
        )
        if syndic_finger:
            if (
                salt.utils.pem_finger(m_pub_fn, sum_type=self.opts["hash_type"])
                != syndic_finger
            ):
                self._finger_fail(syndic_finger, m_pub_fn)
    else:
        if self.opts.get("master_finger", False):
            if (
                salt.utils.pem_finger(m_pub_fn, sum_type=self.opts["hash_type"])
                != self.opts["master_finger"]
            ):
                self._finger_fail(self.opts["master_finger"], m_pub_fn)
    auth["publish_port"] = payload["publish_port"]
    return auth


# Traceback (TypeError)
cent6_2:
provider: vcenter02
clonefrom: CentOS6.6_64bit
num_cpus: 2
memory: 2GB
domain: domain.com
dns_servers:
- 192.168.14.11
- 192.168.14.12
resourcepool: Resources
cluster: qa
datastore: datastore1
datacenter: dlsb
host: hostname
power_on: True
deploy: True
ssh_username: root
password: passwd
minion:
master: 192.168.40.43
grains:
location: ny
env: qa
role: web


cloud.maps.d]# cat map.conf
cent6_2:
- dlsbweb01:
devices:
network:
Network adapter 1:
name: Kickstart Network
switch_type: standard
ip: 192.168.40.248
gateway: [192.168.40.1]
subnet_mask: 255.255.255.0
- dlsbweb02:
devices:
network:
Network adapter 1:
name: Kickstart Network
switch_type: standard
ip: 192.168.40.249
gateway: [192.168.40.1]
subnet_mask: 255.255.255.0


[DEBUG   ] Connection to 192.168.40.249 closed.
[DEBUG   ]  *  INFO: Salt installed!
[DEBUG   ] Connection to 192.168.40.248 closed.
[DEBUG   ]  *  INFO: Salt installed!
[DEBUG   ] Executed command "/tmp/.saltcloud-73e57e99-789c-4379-bc47-6410b7a78c74/deploy.sh -c '/tmp/.saltcloud-73e57e99-789c-4379-bc47-6410b7a78c74'"
[DEBUG   ] SSH command: "ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.249 rm -f '/tmp/.saltcloud-73e57e99-789c-4379-bc47-6410b7a78c74/deploy.sh'"
[DEBUG   ] Executed command "/tmp/.saltcloud-8f078916-9324-44ba-b4a9-c0db91995654/deploy.sh -c '/tmp/.saltcloud-8f078916-9324-44ba-b4a9-c0db91995654'"
[DEBUG   ] SSH command: "ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.248 rm -f '/tmp/.saltcloud-8f078916-9324-44ba-b4a9-c0db91995654/deploy.sh'"
[DEBUG   ] Child Forked! PID: 15369  STDOUT_FD: 21  STDERR_FD: 23
[DEBUG   ] Child Forked! PID: 15370  STDOUT_FD: 21  STDERR_FD: 23
[DEBUG   ] Terminal Command: /bin/sh -c ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.248 'rm -f '"'"'/tmp/.saltcloud-8f078916-9324-44ba-b4a9-c0db91995654/deploy.sh'"'"''
[DEBUG   ] Terminal Command: /bin/sh -c ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.249 'rm -f '"'"'/tmp/.saltcloud-73e57e99-789c-4379-bc47-6410b7a78c74/deploy.sh'"'"''
[DEBUG   ] Warning: Permanently added '192.168.40.249' (RSA) to the list of known hosts.
[DEBUG   ] root@192.168.40.249's password:
[DEBUG   ] Warning: Permanently added '192.168.40.248' (RSA) to the list of known hosts.
[DEBUG   ] root@192.168.40.248's password:
[DEBUG   ] Connection to 192.168.40.249 closed.
[DEBUG   ] Connection to 192.168.40.248 closed.
[DEBUG   ] Removed /tmp/.saltcloud-73e57e99-789c-4379-bc47-6410b7a78c74/deploy.sh
[DEBUG   ] Removed /tmp/.saltcloud-8f078916-9324-44ba-b4a9-c0db91995654/deploy.sh
[DEBUG   ] SSH command: "ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.249 rm -f '/tmp/.saltcloud-73e57e99-789c-4379-bc47-6410b7a78c74/minion.pub'"
[DEBUG   ] SSH command: "ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.248 rm -f '/tmp/.saltcloud-8f078916-9324-44ba-b4a9-c0db91995654/minion.pub'"
[DEBUG   ] Child Forked! PID: 15372  STDOUT_FD: 21  STDERR_FD: 23
[DEBUG   ] Child Forked! PID: 15373  STDOUT_FD: 21  STDERR_FD: 23
[DEBUG   ] Terminal Command: /bin/sh -c ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.248 'rm -f '"'"'/tmp/.saltcloud-8f078916-9324-44ba-b4a9-c0db91995654/minion.pub'"'"''
[DEBUG   ] Terminal Command: /bin/sh -c ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.249 'rm -f '"'"'/tmp/.saltcloud-73e57e99-789c-4379-bc47-6410b7a78c74/minion.pub'"'"''
[DEBUG   ] Warning: Permanently added '192.168.40.249' (RSA) to the list of known hosts.
[DEBUG   ] Warning: Permanently added '192.168.40.248' (RSA) to the list of known hosts.
[DEBUG   ] root@192.168.40.249's password:
[DEBUG   ] root@192.168.40.248's password:
[DEBUG   ] Connection to 192.168.40.249 closed.
[DEBUG   ] Connection to 192.168.40.248 closed.
[DEBUG   ] Removed /tmp/.saltcloud-8f078916-9324-44ba-b4a9-c0db91995654/minion.pub
[DEBUG   ] Removed /tmp/.saltcloud-73e57e99-789c-4379-bc47-6410b7a78c74/minion.pub
[DEBUG   ] SSH command: "ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.248 rm -f '/tmp/.saltcloud-8f078916-9324-44ba-b4a9-c0db91995654/minion.pem'"
[DEBUG   ] SSH command: "ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.249 rm -f '/tmp/.saltcloud-73e57e99-789c-4379-bc47-6410b7a78c74/minion.pem'"
[DEBUG   ] Child Forked! PID: 15374  STDOUT_FD: 21  STDERR_FD: 23
[DEBUG   ] Child Forked! PID: 15375  STDOUT_FD: 21  STDERR_FD: 23
[DEBUG   ] Terminal Command: /bin/sh -c ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.248 'rm -f '"'"'/tmp/.saltcloud-8f078916-9324-44ba-b4a9-c0db91995654/minion.pem'"'"''
[DEBUG   ] Terminal Command: /bin/sh -c ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.249 'rm -f '"'"'/tmp/.saltcloud-73e57e99-789c-4379-bc47-6410b7a78c74/minion.pem'"'"''
[DEBUG   ] Warning: Permanently added '192.168.40.248' (RSA) to the list of known hosts.
[DEBUG   ] Warning: Permanently added '192.168.40.249' (RSA) to the list of known hosts.
[DEBUG   ] root@192.168.40.249's password:
[DEBUG   ] root@192.168.40.248's password:
[DEBUG   ] Connection to 192.168.40.249 closed.
[DEBUG   ] Connection to 192.168.40.248 closed.
[DEBUG   ] Removed /tmp/.saltcloud-8f078916-9324-44ba-b4a9-c0db91995654/minion.pem
[DEBUG   ] Removed /tmp/.saltcloud-73e57e99-789c-4379-bc47-6410b7a78c74/minion.pem
[DEBUG   ] SSH command: "ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.248 rm -f '/tmp/.saltcloud-8f078916-9324-44ba-b4a9-c0db91995654/grains'"
[DEBUG   ] SSH command: "ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.249 rm -f '/tmp/.saltcloud-73e57e99-789c-4379-bc47-6410b7a78c74/grains'"
[DEBUG   ] Child Forked! PID: 15376  STDOUT_FD: 21  STDERR_FD: 23
[DEBUG   ] Child Forked! PID: 15377  STDOUT_FD: 21  STDERR_FD: 23
[DEBUG   ] Terminal Command: /bin/sh -c ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.248 'rm -f '"'"'/tmp/.saltcloud-8f078916-9324-44ba-b4a9-c0db91995654/grains'"'"''
[DEBUG   ] Terminal Command: /bin/sh -c ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.249 'rm -f '"'"'/tmp/.saltcloud-73e57e99-789c-4379-bc47-6410b7a78c74/grains'"'"''
[DEBUG   ] Warning: Permanently added '192.168.40.249' (RSA) to the list of known hosts.
[DEBUG   ] root@192.168.40.249's password:
[DEBUG   ] Warning: Permanently added '192.168.40.248' (RSA) to the list of known hosts.
[DEBUG   ] root@192.168.40.248's password:
[DEBUG   ] Connection to 192.168.40.249 closed.
[DEBUG   ] Connection to 192.168.40.248 closed.
[DEBUG   ] Removed /tmp/.saltcloud-73e57e99-789c-4379-bc47-6410b7a78c74/grains
[DEBUG   ] Removed /tmp/.saltcloud-8f078916-9324-44ba-b4a9-c0db91995654/grains
[DEBUG   ] SSH command: "ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.249 rm -f '/tmp/.saltcloud-73e57e99-789c-4379-bc47-6410b7a78c74/minion'"
[DEBUG   ] SSH command: "ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.248 rm -f '/tmp/.saltcloud-8f078916-9324-44ba-b4a9-c0db91995654/minion'"
[DEBUG   ] Child Forked! PID: 15378  STDOUT_FD: 21  STDERR_FD: 23
[DEBUG   ] Child Forked! PID: 15379  STDOUT_FD: 21  STDERR_FD: 23
[DEBUG   ] Terminal Command: /bin/sh -c ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.248 'rm -f '"'"'/tmp/.saltcloud-8f078916-9324-44ba-b4a9-c0db91995654/minion'"'"''
[DEBUG   ] Terminal Command: /bin/sh -c ssh -t -t -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oControlPath=none -p 22 root@192.168.40.249 'rm -f '"'"'/tmp/.saltcloud-73e57e99-789c-4379-bc47-6410b7a78c74/minion'"'"''
[DEBUG   ] Warning: Permanently added '192.168.40.248' (RSA) to the list of known hosts.
[DEBUG   ] Warning: Permanently added '192.168.40.249' (RSA) to the list of known hosts.
[DEBUG   ] root@192.168.40.248's password:
[DEBUG   ] root@192.168.40.249's password:
[DEBUG   ] Connection to 192.168.40.248 closed.
[DEBUG   ] Connection to 192.168.40.249 closed.
[DEBUG   ] Removed /tmp/.saltcloud-73e57e99-789c-4379-bc47-6410b7a78c74/minion
[DEBUG   ] Removed /tmp/.saltcloud-8f078916-9324-44ba-b4a9-c0db91995654/minion
[DEBUG   ] MasterEvent PUB socket URI: ipc:///var/run/salt/master/master_event_pub.ipc
[DEBUG   ] MasterEvent PUB socket URI: ipc:///var/run/salt/master/master_event_pub.ipc
[DEBUG   ] MasterEvent PULL socket URI: ipc:///var/run/salt/master/master_event_pull.ipc
[DEBUG   ] MasterEvent PULL socket URI: ipc:///var/run/salt/master/master_event_pull.ipc
[DEBUG   ] Sending event - data = {'host': '192.168.40.249', 'name': 'dlsbweb02', '_stamp': '2016-03-02T18:19:36.067144', 'event': 'dlsbweb02 has been deployed at 192.168.40.249'}
[DEBUG   ] Sending event - data = {'host': '192.168.40.248', 'name': 'dlsbweb01', '_stamp': '2016-03-02T18:19:36.067528', 'event': 'dlsbweb01 has been deployed at 192.168.40.248'}
[INFO    ] Salt installed on dlsbweb02
[INFO    ] Salt installed on dlsbweb01
[DEBUG   ] MasterEvent PUB socket URI: ipc:///var/run/salt/master/master_event_pub.ipc
[DEBUG   ] MasterEvent PULL socket URI: ipc:///var/run/salt/master/master_event_pull.ipc
[DEBUG   ] Sending event - data = {'profile': 'cent6_2', 'event': 'created instance', '_stamp': '2016-03-02T18:19:36.922794', 'name': 'dlsbweb01', 'provider': 'vcenter02:vmware'}
[DEBUG   ] MasterEvent PUB socket URI: ipc:///var/run/salt/master/master_event_pub.ipc
[DEBUG   ] MasterEvent PULL socket URI: ipc:///var/run/salt/master/master_event_pull.ipc
[DEBUG   ] Sending event - data = {'profile': 'cent6_2', 'event': 'created instance', '_stamp': '2016-03-02T18:19:36.932306', 'name': 'dlsbweb02', 'provider': 'vcenter02:vmware'}
[ERROR   ] There was a query error: itervalues() takes exactly 1 argument (2 given)
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/cloud/cli.py", line 339, in run
ret = mapper.run_map(dmap)
File "/usr/lib/python2.6/site-packages/salt/cloud/__init__.py", line 2211, in run_map
lambda x: x['level']):
TypeError: itervalues() takes exactly 1 argument (2 given)

salt --versions-report
Salt Version:
Salt: 2015.8.5

Dependency Versions:
Jinja2: 2.2.1
M2Crypto: 0.20.2
Mako: Not Installed
PyYAML: 3.11
PyZMQ: 14.5.0
Python: 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
RAET: Not Installed
Tornado: 4.2.1
ZMQ: 4.0.5
cffi: Not Installed
cherrypy: Not Installed
dateutil: 1.4.1
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
libgit2: Not Installed
libnacl: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.4.6
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pygit2: Not Installed
python-gnupg: Not Installed
smmap: Not Installed
timelib: Not Installed

System Versions:
dist: centos 6.7 Final
machine: x86_64
release: 2.6.32-504.el6.x86_64
system: CentOS 6.7 Final

# Fixed code
def sign_in(self, timeout=60, safe=True, tries=1, channel=None):
    """
    Send a sign in request to the master, sets the key information and
    returns a dict containing the master publish interface to bind to
    and the decrypted aes key for transport decryption.

    :param int timeout: Number of seconds to wait before timing out the sign-in request
    :param bool safe: If True, do not raise an exception on timeout. Retry instead.
    :param int tries: The number of times to try to authenticate before giving up.

    :raises SaltReqTimeoutError: If the sign-in request has timed out and :param safe: is not set

    :return: Return a string on failure indicating the reason for failure. On success, return a dictionary
    with the publication port and the shared AES key.

    """
    auth = {}

    auth_timeout = self.opts.get("auth_timeout", None)
    if auth_timeout is not None:
        timeout = auth_timeout
    auth_safemode = self.opts.get("auth_safemode", None)
    if auth_safemode is not None:
        safe = auth_safemode
    auth_tries = self.opts.get("auth_tries", None)
    if auth_tries is not None:
        tries = auth_tries

    m_pub_fn = os.path.join(self.opts["pki_dir"], self.mpub)

    auth["master_uri"] = self.opts["master_uri"]

    if not channel:
        channel = salt.transport.client.ReqChannel.factory(self.opts, crypt="clear")

    sign_in_payload = self.minion_sign_in_payload()
    try:
        payload = channel.send(sign_in_payload, tries=tries, timeout=timeout)
    except SaltReqTimeoutError as e:
        if safe:
            log.warning("SaltReqTimeoutError: {0}".format(e))
            return "retry"
        raise SaltClientError("Attempt to authenticate with the salt master failed")

    if "load" in payload:
        if "ret" in payload["load"]:
            if not payload["load"]["ret"]:
                if self.opts["rejected_retry"]:
                    log.error(
                        "The Salt Master has rejected this minion's public "
                        "key.\nTo repair this issue, delete the public key "
                        "for this minion on the Salt Master.\nThe Salt "
                        "Minion will attempt to to re-authenicate."
                    )
                    return "retry"
                else:
                    log.critical(
                        "The Salt Master has rejected this minion's public "
                        "key!\nTo repair this issue, delete the public key "
                        "for this minion on the Salt Master and restart this "
                        "minion.\nOr restart the Salt Master in open mode to "
                        "clean out the keys. The Salt Minion will now exit."
                    )
                    sys.exit(salt.defaults.exitcodes.EX_OK)
            # has the master returned that its maxed out with minions?
            elif payload["load"]["ret"] == "full":
                return "full"
            else:
                log.error(
                    "The Salt Master has cached the public key for this "
                    "node. If this is the first time connecting to this master "
                    "then this key may need to be accepted using 'salt-key -a {0}' on "
                    "the salt master. This salt minion will wait for {1} seconds "
                    "before attempting to re-authenticate.".format(
                        self.opts["id"], self.opts["acceptance_wait_time"]
                    )
                )
                return "retry"
    auth["aes"] = self.verify_master(payload, master_pub="token" in sign_in_payload)
    if not auth["aes"]:
        log.critical(
            "The Salt Master server's public key did not authenticate!\n"
            "The master may need to be updated if it is a version of Salt "
            "lower than {0}, or\n"
            "If you are confident that you are connecting to a valid Salt "
            "Master, then remove the master public key and restart the "
            "Salt Minion.\nThe master public key can be found "
            "at:\n{1}".format(salt.version.__version__, m_pub_fn)
        )
        sys.exit(42)
    if self.opts.get("syndic_master", False):  # Is syndic
        syndic_finger = self.opts.get(
            "syndic_finger", self.opts.get("master_finger", False)
        )
        if syndic_finger:
            if (
                salt.utils.pem_finger(m_pub_fn, sum_type=self.opts["hash_type"])
                != syndic_finger
            ):
                self._finger_fail(syndic_finger, m_pub_fn)
    else:
        if self.opts.get("master_finger", False):
            if (
                salt.utils.pem_finger(m_pub_fn, sum_type=self.opts["hash_type"])
                != self.opts["master_finger"]
            ):
                self._finger_fail(self.opts["master_finger"], m_pub_fn)
    auth["publish_port"] = payload["publish_port"]
    return auth