Example #1
0
    def test_ansible_inventory_headding_mangling(self):
        g = inventory.AnsibleInventoryGroup('[foobar]')
        self.assertEquals(g.heading, '[foobar]')
        self.assertEquals(g.name, 'foobar')

        g = inventory.AnsibleInventoryGroup('foobar]')
        self.assertEquals(g.heading, '[foobar]')
        self.assertEquals(g.name, 'foobar')

        g = inventory.AnsibleInventoryGroup('foobar')
        self.assertEquals(g.heading, '[foobar]')
        self.assertEquals(g.name, 'foobar')
Example #2
0
    def test_ansible_inventory_group_items(self):
        base = 'localhost foo=bar bar=baz'
        h = inventory.AnsibleInventoryHost.from_string(base)

        g = inventory.AnsibleInventoryGroup('[foobar]', [base])

        self.assertEquals(len(g.items), 1)
        self.assertEquals(g.items[0], h)

        g2 = inventory.AnsibleInventoryGroup('[foobar]', [h])

        self.assertEquals(len(g2.items), 1)
        self.assertEquals(g.items[0], g2.items[0])
Example #3
0
    def test_simple_inventory_list_and_dict(self):
        target = inventory.AnsibleInventory(
            ['localhost', 'localhost2'],
            sections=[
                inventory.AnsibleInventoryGroup('test',
                                                ['localhost', 'localhost2'])
            ])

        source = inventory.simple_inventory(
            ['localhost', 'localhost2'], {"test": ["localhost", "localhost2"]})

        self.assertEquals(source.to_string(), target.to_string())
Example #4
0
    def test_ansible_inventory_api(self):
        headers = ['localhost foo=bar baz=bar', 'localhost baz=bar foo=bar']
        body = '''
[some_group]
localhost foo=other
192.168.1.10

[another group]
192.168.1.10

'''
        targets = ['%s\n%s' % (h, body) for h in headers]
        i = inventory.AnsibleInventory(
            ['localhost foo=bar baz=bar'],
            sections=[
                inventory.AnsibleInventoryGroup(
                    'some_group', ['localhost foo=other', '192.168.1.10']),
                inventory.AnsibleInventoryGroup('another group',
                                                ['192.168.1.10'])
            ])

        self.assertIn(i.to_string(), targets)
Example #5
0
 def test_ansible_inventory_group_set_name(self):
     g = inventory.AnsibleInventoryGroup('[foobar]')
     g.name = 'FOOBAR'
     self.assertEquals(g.name, 'FOOBAR')
     self.assertEquals(g.heading, '[FOOBAR]')
Example #6
0
 def test_ansible_inventory_group_name(self):
     g = inventory.AnsibleInventoryGroup('[foobar]')
     self.assertEquals(g.heading, '[foobar]')
     self.assertEquals(g.name, 'foobar')