def remove(host: Host, ansible_runner: AnsibleRunner, rancher_client: RancherClient) -> bool: ansible_runner.add_host(host) log.info(f'Removing {host} from environment') rancher_host = rancher_client.get_host(host.address) if rancher_host is None: log.warning(f'Host {host.address} was not found in rancher, skipping') return False deleted_from_rancher = rancher_client.delete_host(rancher_host) if not deleted_from_rancher: log.warning( f'Host {host} was not deleted from Rancher master, skipping') return False return ansible_runner.play( f'{_playbook_path}/remove_host.yml', targets=[host.address] )
def add(host: Host, ansible_runner: AnsibleRunner, rancher: RancherClient, pip_executable: str = 'pip', pip_as_root: bool = True) -> bool: ansible_runner.add_host(host) log.info(f'Adding {host} to environment') return ansible_runner.play( f'{_playbook_path}/add_host.yml', targets=[host.address], extra_vars={ 'RANCHER_SERVER_URL': rancher.url, 'RANCHER_ENV_ID': rancher.env_id, 'RANCHER_REG_TOKEN': rancher.get_registration_token(), 'HOST_ID': host.address, 'HOST_TYPE': host.variables['type'], 'HOST_SITE': host.variables['site'], 'PIP_EXECUTABLE': pip_executable, 'PIP_AS_ROOT': 'yes' if pip_as_root else 'no', 'EXTRA_LABELS': host.variables['extra_labels'] } )