コード例 #1
0
    def test_09_host_remove(self):
        """remove a host from an existent group
        """
        inventory = AnsibleInventory(INV_FILENAME, excl=True)
        inventory.group_add('mygroup')
        self.assertIn('mygroup', inventory.groups)

        # two write operations not supported..
        # Needed another AnsibleInventary Object
        inventory = AnsibleInventory(INV_FILENAME, excl=True)
        inventory.host_add('mygroup', 'myhost')
        self.assertIn('myhost', inventory.group_show('mygroup'))

        # two write operations not supported..
        # Needed another AnsibleInventary Object
        inventory = AnsibleInventory(INV_FILENAME, excl=True)
        inventory.host_remove('mygroup', 'myhost')
        self.assertNotIn('myhost', inventory.group_show('mygroup'))
コード例 #2
0
ファイル: hosts.py プロジェクト: lamtov/lamtv10_ops
def remove_host(host_name, group_name):
    r = APIResponse()
    inventory = AnsibleInventory(excl=True)

    if not inventory.loaded:
        r.status, r.msg = "LOCKED", "Unable to lock the inventory file, " \
                                    "try later"
        return r

    if (group_name not in inventory.groups
            or host_name not in inventory.group_show(group_name)):
        # invalid request
        r.status, r.msg = "INVALID", "No such group found in the inventory"
        inventory.unlock()
        return r

    # At this point the removal is ok
    inventory.host_remove(group_name, host_name)
    r.status = "OK"

    return r