Merge "Change ansible_ssh_host to ansible_host"
This commit is contained in:
commit
6b99f21d63
|
@ -45,16 +45,16 @@ $ sudo apt-get install python-dev python-pip gcc libssl-dev libffi-dev
|
|||
$ pip install kargo
|
||||
$ kargo --noclone -i inventory.cfg prepare \
|
||||
--nodes \
|
||||
node1[ansible_ssh_host=10.90.0.2,ip=10.90.0.2] \
|
||||
node2[ansible_ssh_host=10.90.0.3,ip=10.90.0.3] \
|
||||
node3[ansible_ssh_host=10.90.0.4,ip=10.90.0.4] \
|
||||
node1[ansible_host=10.90.0.2,ip=10.90.0.2] \
|
||||
node2[ansible_host=10.90.0.3,ip=10.90.0.3] \
|
||||
node3[ansible_host=10.90.0.4,ip=10.90.0.4] \
|
||||
--etcds \
|
||||
node4[ansible_ssh_host=10.90.0.5,ip=10.90.0.5] \
|
||||
node5[ansible_ssh_host=10.90.0.6,ip=10.90.0.6] \
|
||||
node6[ansible_ssh_host=10.90.0.7,ip=10.90.0.7] \
|
||||
node4[ansible_host=10.90.0.5,ip=10.90.0.5] \
|
||||
node5[ansible_host=10.90.0.6,ip=10.90.0.6] \
|
||||
node6[ansible_host=10.90.0.7,ip=10.90.0.7] \
|
||||
--masters \
|
||||
node7[ansible_ssh_host=10.90.0.5,ip=10.90.0.8] \
|
||||
node8[ansible_ssh_host=10.90.0.6,ip=10.90.0.9]
|
||||
node7[ansible_host=10.90.0.5,ip=10.90.0.8] \
|
||||
node8[ansible_host=10.90.0.6,ip=10.90.0.9]
|
||||
|
||||
This allows more granular control over role distribution, but kargo-cli has
|
||||
several dependencies because it several other functions.
|
||||
|
|
|
@ -3,9 +3,9 @@ node1
|
|||
node2
|
||||
|
||||
[all]
|
||||
node1 ansible_ssh_host=10.90.0.2 ip=10.90.0.2
|
||||
node2 ansible_ssh_host=10.90.0.3 ip=10.90.0.3
|
||||
node3 ansible_ssh_host=10.90.0.4 ip=10.90.0.4
|
||||
node1 ansible_host=10.90.0.2 ip=10.90.0.2
|
||||
node2 ansible_host=10.90.0.3 ip=10.90.0.3
|
||||
node3 ansible_host=10.90.0.4 ip=10.90.0.4
|
||||
|
||||
[k8s-cluster:children]
|
||||
kube-node
|
||||
|
|
|
@ -34,7 +34,7 @@ class TestInventory(unittest.TestCase):
|
|||
self.inv = inventory.KargoInventory()
|
||||
|
||||
def test_get_ip_from_opts(self):
|
||||
optstring = "ansible_ssh_host=10.90.3.2 ip=10.90.3.2"
|
||||
optstring = "ansible_host=10.90.3.2 ip=10.90.3.2"
|
||||
expected = "10.90.3.2"
|
||||
result = self.inv.get_ip_from_opts(optstring)
|
||||
self.assertEqual(expected, result)
|
||||
|
@ -67,14 +67,14 @@ class TestInventory(unittest.TestCase):
|
|||
def test_build_hostnames_add_one(self):
|
||||
changed_hosts = ['10.90.0.2']
|
||||
expected = OrderedDict([('node1',
|
||||
'ansible_ssh_host=10.90.0.2 ip=10.90.0.2')])
|
||||
'ansible_host=10.90.0.2 ip=10.90.0.2')])
|
||||
result = self.inv.build_hostnames(changed_hosts)
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test_build_hostnames_add_duplicate(self):
|
||||
changed_hosts = ['10.90.0.2']
|
||||
expected = OrderedDict([('node1',
|
||||
'ansible_ssh_host=10.90.0.2 ip=10.90.0.2')])
|
||||
'ansible_host=10.90.0.2 ip=10.90.0.2')])
|
||||
self.inv.config['all'] = expected
|
||||
result = self.inv.build_hostnames(changed_hosts)
|
||||
self.assertEqual(expected, result)
|
||||
|
@ -82,8 +82,8 @@ class TestInventory(unittest.TestCase):
|
|||
def test_build_hostnames_add_two(self):
|
||||
changed_hosts = ['10.90.0.2', '10.90.0.3']
|
||||
expected = OrderedDict([
|
||||
('node1', 'ansible_ssh_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_ssh_host=10.90.0.3 ip=10.90.0.3')])
|
||||
('node1', 'ansible_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_host=10.90.0.3 ip=10.90.0.3')])
|
||||
self.inv.config['all'] = OrderedDict()
|
||||
result = self.inv.build_hostnames(changed_hosts)
|
||||
self.assertEqual(expected, result)
|
||||
|
@ -91,11 +91,11 @@ class TestInventory(unittest.TestCase):
|
|||
def test_build_hostnames_delete_first(self):
|
||||
changed_hosts = ['-10.90.0.2']
|
||||
existing_hosts = OrderedDict([
|
||||
('node1', 'ansible_ssh_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_ssh_host=10.90.0.3 ip=10.90.0.3')])
|
||||
('node1', 'ansible_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_host=10.90.0.3 ip=10.90.0.3')])
|
||||
self.inv.config['all'] = existing_hosts
|
||||
expected = OrderedDict([
|
||||
('node2', 'ansible_ssh_host=10.90.0.3 ip=10.90.0.3')])
|
||||
('node2', 'ansible_host=10.90.0.3 ip=10.90.0.3')])
|
||||
result = self.inv.build_hostnames(changed_hosts)
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
|
@ -103,8 +103,8 @@ class TestInventory(unittest.TestCase):
|
|||
hostname = 'node1'
|
||||
expected = True
|
||||
existing_hosts = OrderedDict([
|
||||
('node1', 'ansible_ssh_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_ssh_host=10.90.0.3 ip=10.90.0.3')])
|
||||
('node1', 'ansible_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_host=10.90.0.3 ip=10.90.0.3')])
|
||||
result = self.inv.exists_hostname(existing_hosts, hostname)
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
|
@ -112,8 +112,8 @@ class TestInventory(unittest.TestCase):
|
|||
hostname = 'node99'
|
||||
expected = False
|
||||
existing_hosts = OrderedDict([
|
||||
('node1', 'ansible_ssh_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_ssh_host=10.90.0.3 ip=10.90.0.3')])
|
||||
('node1', 'ansible_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_host=10.90.0.3 ip=10.90.0.3')])
|
||||
result = self.inv.exists_hostname(existing_hosts, hostname)
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
|
@ -121,8 +121,8 @@ class TestInventory(unittest.TestCase):
|
|||
ip = '10.90.0.2'
|
||||
expected = True
|
||||
existing_hosts = OrderedDict([
|
||||
('node1', 'ansible_ssh_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_ssh_host=10.90.0.3 ip=10.90.0.3')])
|
||||
('node1', 'ansible_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_host=10.90.0.3 ip=10.90.0.3')])
|
||||
result = self.inv.exists_ip(existing_hosts, ip)
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
|
@ -130,26 +130,26 @@ class TestInventory(unittest.TestCase):
|
|||
ip = '10.90.0.200'
|
||||
expected = False
|
||||
existing_hosts = OrderedDict([
|
||||
('node1', 'ansible_ssh_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_ssh_host=10.90.0.3 ip=10.90.0.3')])
|
||||
('node1', 'ansible_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_host=10.90.0.3 ip=10.90.0.3')])
|
||||
result = self.inv.exists_ip(existing_hosts, ip)
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test_delete_host_by_ip_positive(self):
|
||||
ip = '10.90.0.2'
|
||||
expected = OrderedDict([
|
||||
('node2', 'ansible_ssh_host=10.90.0.3 ip=10.90.0.3')])
|
||||
('node2', 'ansible_host=10.90.0.3 ip=10.90.0.3')])
|
||||
existing_hosts = OrderedDict([
|
||||
('node1', 'ansible_ssh_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_ssh_host=10.90.0.3 ip=10.90.0.3')])
|
||||
('node1', 'ansible_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_host=10.90.0.3 ip=10.90.0.3')])
|
||||
self.inv.delete_host_by_ip(existing_hosts, ip)
|
||||
self.assertEqual(expected, existing_hosts)
|
||||
|
||||
def test_delete_host_by_ip_negative(self):
|
||||
ip = '10.90.0.200'
|
||||
existing_hosts = OrderedDict([
|
||||
('node1', 'ansible_ssh_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_ssh_host=10.90.0.3 ip=10.90.0.3')])
|
||||
('node1', 'ansible_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_host=10.90.0.3 ip=10.90.0.3')])
|
||||
self.assertRaisesRegexp(ValueError, "Unable to find host",
|
||||
self.inv.delete_host_by_ip, existing_hosts, ip)
|
||||
|
||||
|
@ -157,8 +157,8 @@ class TestInventory(unittest.TestCase):
|
|||
proper_hostnames = ['node1', 'node2']
|
||||
bad_host = 'doesnotbelong2'
|
||||
existing_hosts = OrderedDict([
|
||||
('node1', 'ansible_ssh_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_ssh_host=10.90.0.3 ip=10.90.0.3'),
|
||||
('node1', 'ansible_host=10.90.0.2 ip=10.90.0.2'),
|
||||
('node2', 'ansible_host=10.90.0.3 ip=10.90.0.3'),
|
||||
('doesnotbelong2', 'whateveropts=ilike')])
|
||||
self.inv.config['all'] = existing_hosts
|
||||
self.inv.purge_invalid_hosts(proper_hostnames)
|
||||
|
|
|
@ -127,7 +127,7 @@ class KargoInventory(object):
|
|||
|
||||
next_host = "{0}{1}".format(HOST_PREFIX, next_host_id)
|
||||
next_host_id += 1
|
||||
all_hosts[next_host] = "ansible_ssh_host={0} ip={1}".format(
|
||||
all_hosts[next_host] = "ansible_host={0} ip={1}".format(
|
||||
host, host)
|
||||
elif host[0].isalpha():
|
||||
raise Exception("Adding hosts by hostname is not supported.")
|
||||
|
|
Loading…
Reference in New Issue