#288 Prevent running playbooks on localhost.
Merged 5 years ago by astepano. Opened 5 years ago by astepano.

@@ -18,6 +18,20 @@ 

  import logging

  

  

+ def print_bad_inventory(exctype, value, tb):

+     """Print empty inventory on any uncatched exception. This will prevent

+     running playbook on localhost.

+     """

+     hosts = ["fake_hostname_failed_inventory"]

+     bad_inv = {"localhost": {"hosts": hosts, "vars": {}},

+                "subjects": {"hosts": hosts, "vars": {}},

+                "_meta": {"hostvars": {}}}

+     sys.stdout.write(json.dumps(bad_inv, indent=4, separators=(',', ': ')))

+ 

+ 

+ sys.excepthook = print_bad_inventory

+ 

+ 

  EMPTY_INVENTORY = {}

  LOG_FILE = "default_provisioners.log"

  

@@ -11,6 +11,21 @@ 

  import errno

  import distutils.util

  

+ 

+ def print_bad_inventory(exctype, value, tb):

+     """Print empty inventory on any uncatched exception. This will prevent

+     running playbook on localhost.

+     """

+     hosts = ["fake_hostname_failed_inventory"]

+     bad_inv = {"localhost": {"hosts": hosts, "vars": {}},

+                "subjects": {"hosts": hosts, "vars": {}},

+                "_meta": {"hostvars": {}}}

+     sys.stdout.write(json.dumps(bad_inv, indent=4, separators=(',', ': ')))

+ 

+ 

+ sys.excepthook = print_bad_inventory

+ 

+ 

  EMPTY_INVENTORY = {}

  LOG_FILE = "default_provisioners.log"

  

@@ -21,6 +21,21 @@ 

  

  import yaml

  

+ 

+ def print_bad_inventory(exctype, value, tb):

+     """Print empty inventory on any uncatched exception. This will prevent

+     running playbook on localhost.

+     """

+     hosts = ["fake_hostname_failed_inventory"]

+     bad_inv = {"localhost": {"hosts": hosts, "vars": {}},

+                "subjects": {"hosts": hosts, "vars": {}},

+                "_meta": {"hostvars": {}}}

+     sys.stdout.write(json.dumps(bad_inv, indent=4, separators=(',', ': ')))

+ 

+ 

+ sys.excepthook = print_bad_inventory

+ 

+ 

  IDENTITY = """

  -----BEGIN RSA PRIVATE KEY-----

  MIIEpQIBAAKCAQEA1DrTSXQRF8isQQfPfK3U+eFC4zBrjur+Iy15kbHUYUeSHf5S

@@ -14,6 +14,21 @@ 

  import errno

  import distutils.util

  

+ 

+ def print_bad_inventory(exctype, value, tb):

+     """Print empty inventory on any uncatched exception. This will prevent

+     running playbook on localhost.

+     """

+     hosts = ["fake_hostname_failed_inventory"]

+     bad_inv = {"localhost": {"hosts": hosts, "vars": {}},

+                "subjects": {"hosts": hosts, "vars": {}},

+                "_meta": {"hostvars": {}}}

+     sys.stdout.write(json.dumps(bad_inv, indent=4, separators=(',', ': ')))

+ 

+ 

+ sys.excepthook = print_bad_inventory

+ 

+ 

  EMPTY_INVENTORY = {}

  LOG_FILE = "default_provisioners.log"

  

Inventory provisioners may fail. If provision script fail playbook may
run on localhost system. This change will prevent running playbook on
localhost when one of inventory script fail.

Signed-off-by: Andrei Stepanov astepano@redhat.com

rebased onto 1e0ef56

5 years ago

Commit cafd1e4 fixes this pull-request

Pull-Request has been merged by astepano

5 years ago

Pull-Request has been merged by astepano

5 years ago