Blame README-host.md

Packit 8cb997
Host module
Packit 8cb997
===========
Packit 8cb997
Packit 8cb997
Description
Packit 8cb997
-----------
Packit 8cb997
Packit 8cb997
The host module allows to ensure presence, absence and disablement of hosts.
Packit 8cb997
Packit 8cb997
The host module is as compatible as possible to the Ansible upstream `ipa_host` module, but additionally offers to disable hosts.
Packit 8cb997
Packit 8cb997
Packit 8cb997
Features
Packit 8cb997
--------
Packit 8cb997
* Host management
Packit 8cb997
Packit 8cb997
Packit 8cb997
Supported FreeIPA Versions
Packit 8cb997
--------------------------
Packit 8cb997
Packit 8cb997
FreeIPA versions 4.4.0 and up are supported by the ipahost module.
Packit 8cb997
Packit 8cb997
Packit 8cb997
Requirements
Packit 8cb997
------------
Packit 8cb997
Packit 8cb997
**Controller**
Packit 8cb997
* Ansible version: 2.8+
Packit 8cb997
Packit 8cb997
**Node**
Packit 8cb997
* Supported FreeIPA version (see above)
Packit 8cb997
Packit 8cb997
Packit 8cb997
Usage
Packit 8cb997
=====
Packit 8cb997
Packit 8cb997
Example inventory file
Packit 8cb997
Packit 8cb997
```ini
Packit 8cb997
[ipaserver]
Packit 8cb997
ipaserver.test.local
Packit 8cb997
```
Packit 8cb997
Packit 8cb997
Packit 8cb997
Example playbook to ensure host presence:
Packit 8cb997
Packit 8cb997
```yaml
Packit 8cb997
---
Packit 8cb997
- name: Playbook to handle hosts
Packit 8cb997
  hosts: ipaserver
Packit 8cb997
  become: true
Packit 8cb997
Packit 8cb997
  tasks:
Packit 8cb997
  # Ensure host is present
Packit 8cb997
  - ipahost:
Packit Service 0f71a7
      ipaadmin_password: SomeADMINpassword
Packit 8cb997
      name: host01.example.com
Packit 8cb997
      description: Example host
Packit 8cb997
      ip_address: 192.168.0.123
Packit 8cb997
      locality: Lab
Packit 8cb997
      ns_host_location: Lab
Packit 8cb997
      ns_os_version: CentOS 7
Packit 8cb997
      ns_hardware_platform: Lenovo T61
Packit 8cb997
      mac_address:
Packit 8cb997
      - "08:00:27:E3:B1:2D"
Packit 8cb997
      - "52:54:00:BD:97:1E"
Packit 8cb997
      state: present
Packit 8cb997
```
Packit Service 0f71a7
Compared to `ipa host-add` command no IP address conflict check is done as the ipahost module supports to have several IPv4 and IPv6 addresses for a host.
Packit Service 0f71a7
Packit Service 0f71a7
Packit Service 0f71a7
Example playbook to ensure host presence with several IP addresses:
Packit Service 0f71a7
Packit Service 0f71a7
```yaml
Packit Service 0f71a7
---
Packit Service 0f71a7
- name: Playbook to handle hosts
Packit Service 0f71a7
  hosts: ipaserver
Packit Service 0f71a7
  become: true
Packit Service 0f71a7
Packit Service 0f71a7
  tasks:
Packit Service 0f71a7
  # Ensure host is present
Packit Service 0f71a7
  - ipahost:
Packit Service 0f71a7
      ipaadmin_password: SomeADMINpassword
Packit Service 0f71a7
      name: host01.example.com
Packit Service 0f71a7
      description: Example host
Packit Service 0f71a7
      ip_address:
Packit Service 0f71a7
      - 192.168.0.123
Packit Service 0f71a7
      - 192.168.0.124
Packit Service 0f71a7
      - fe80::20c:29ff:fe02:a1b3
Packit Service 0f71a7
      - fe80::20c:29ff:fe02:a1b4
Packit Service 0f71a7
      locality: Lab
Packit Service 0f71a7
      ns_host_location: Lab
Packit Service 0f71a7
      ns_os_version: CentOS 7
Packit Service 0f71a7
      ns_hardware_platform: Lenovo T61
Packit Service 0f71a7
      mac_address:
Packit Service 0f71a7
      - "08:00:27:E3:B1:2D"
Packit Service 0f71a7
      - "52:54:00:BD:97:1E"
Packit Service 0f71a7
      state: present
Packit Service 0f71a7
```
Packit Service 0f71a7
Packit Service 0f71a7
Packit Service 0f71a7
Example playbook to ensure IP addresses are present for a host:
Packit Service 0f71a7
Packit Service 0f71a7
```yaml
Packit Service 0f71a7
---
Packit Service 0f71a7
- name: Playbook to handle hosts
Packit Service 0f71a7
  hosts: ipaserver
Packit Service 0f71a7
  become: true
Packit Service 0f71a7
Packit Service 0f71a7
  tasks:
Packit Service 0f71a7
  # Ensure host is present
Packit Service 0f71a7
  - ipahost:
Packit Service 0f71a7
      ipaadmin_password: SomeADMINpassword
Packit Service 0f71a7
      name: host01.example.com
Packit Service 0f71a7
      ip_address:
Packit Service 0f71a7
      - 192.168.0.124
Packit Service 0f71a7
      - fe80::20c:29ff:fe02:a1b4
Packit Service 0f71a7
      action: member
Packit Service 0f71a7
      state: present
Packit Service 0f71a7
```
Packit Service 0f71a7
Packit Service 0f71a7
Packit Service 0f71a7
Example playbook to ensure IP addresses are absent for a host:
Packit Service 0f71a7
Packit Service 0f71a7
```yaml
Packit Service 0f71a7
---
Packit Service 0f71a7
- name: Playbook to handle hosts
Packit Service 0f71a7
  hosts: ipaserver
Packit Service 0f71a7
  become: true
Packit Service 0f71a7
Packit Service 0f71a7
  tasks:
Packit Service 0f71a7
  # Ensure host is present
Packit Service 0f71a7
  - ipahost:
Packit Service 0f71a7
      ipaadmin_password: SomeADMINpassword
Packit Service 0f71a7
      name: host01.example.com
Packit Service 0f71a7
      ip_address:
Packit Service 0f71a7
      - 192.168.0.124
Packit Service 0f71a7
      - fe80::20c:29ff:fe02:a1b4
Packit Service 0f71a7
      action: member
Packit Service 0f71a7
      state: absent
Packit Service 0f71a7
```
Packit 8cb997
Packit 8cb997
Packit 8cb997
Example playbook to ensure host presence without DNS:
Packit 8cb997
Packit 8cb997
```yaml
Packit 8cb997
---
Packit 8cb997
- name: Playbook to handle hosts
Packit 8cb997
  hosts: ipaserver
Packit 8cb997
  become: true
Packit 8cb997
Packit 8cb997
  tasks:
Packit 8cb997
  # Ensure host is present without DNS
Packit 8cb997
  - ipahost:
Packit Service 0f71a7
      ipaadmin_password: SomeADMINpassword
Packit 8cb997
      name: host02.example.com
Packit 8cb997
      description: Example host
Packit 8cb997
      force: yes
Packit 8cb997
```
Packit 8cb997
Packit 8cb997
Packit 8cb997
Example playbook to ensure host presence with a random password:
Packit 8cb997
Packit 8cb997
```yaml
Packit 8cb997
---
Packit 8cb997
- name: Ensure host with random password
Packit 8cb997
  hosts: ipaserver
Packit 8cb997
  become: true
Packit 8cb997
Packit 8cb997
  tasks:
Packit 8cb997
  - name: Host host01.example.com present with random password
Packit 8cb997
    ipahost:
Packit Service 0f71a7
      ipaadmin_password: SomeADMINpassword
Packit 8cb997
      name: host01.example.com
Packit 8cb997
      random: yes
Packit 8cb997
      force: yes
Packit Service 0f71a7
      update_password: on_create
Packit 8cb997
    register: ipahost
Packit 8cb997
Packit 8cb997
  - name: Print generated random password
Packit 8cb997
    debug:
Packit 8cb997
      var: ipahost.host.randompassword
Packit 8cb997
```
Packit Service 0f71a7
Please remember that a new random password will be generated for an existing but not enrolled host if `update_password` is not limited to `on_create`. For an already enrolled host the task will fail with `update_password` default setting `always`.
Packit 8cb997
Packit 8cb997
Example playbook to ensure presence of several hosts with a random password:
Packit 8cb997
Packit 8cb997
```yaml
Packit 8cb997
---
Packit 8cb997
- name: Ensure hosts with random password
Packit 8cb997
  hosts: ipaserver
Packit 8cb997
  become: true
Packit 8cb997
Packit 8cb997
  tasks:
Packit 8cb997
  - name: Hosts host01.example.com and host01.example.com present with random passwords
Packit 8cb997
    ipahost:
Packit Service 0f71a7
      ipaadmin_password: SomeADMINpassword
Packit 8cb997
      hosts:
Packit 8cb997
      - name: host01.example.com
Packit 8cb997
        random: yes
Packit 8cb997
        force: yes
Packit Service 0f71a7
        update_password: on_create
Packit 8cb997
      - name: host02.example.com
Packit 8cb997
        random: yes
Packit 8cb997
        force: yes
Packit Service 0f71a7
        update_password: on_create
Packit 8cb997
    register: ipahost
Packit 8cb997
Packit 8cb997
  - name: Print generated random password for host01.example.com
Packit 8cb997
    debug:
Packit 8cb997
      var: ipahost.host["host01.example.com"].randompassword
Packit 8cb997
Packit 8cb997
  - name: Print generated random password for host02.example.com
Packit 8cb997
    debug:
Packit 8cb997
      var: ipahost.host["host02.example.com"].randompassword
Packit 8cb997
```
Packit Service 0f71a7
Please remember that a new random password will be generated for an existing but not enrolled host if `update_password` is not limited to `on_create`. For an already enrolled host the task will fail with `update_password` default setting `always`.
Packit 8cb997
Packit 8cb997
Packit 8cb997
Example playbook to ensure presence of host member principal:
Packit 8cb997
Packit 8cb997
```yaml
Packit 8cb997
---
Packit 8cb997
- name: Host present with principal
Packit 8cb997
  hosts: ipaserver
Packit 8cb997
  become: true
Packit 8cb997
Packit 8cb997
  tasks:
Packit 8cb997
  - name: Host host01.example.com present with principals host/testhost01.example.com and host/myhost01.example.com
Packit 8cb997
    ipahost:
Packit Service 0f71a7
      ipaadmin_password: SomeADMINpassword
Packit 8cb997
      name: host01.example.com
Packit 8cb997
      principal:
Packit 8cb997
      - host/testhost01.example.com
Packit 8cb997
      - host/myhost01.example.com
Packit 8cb997
      action: member
Packit 8cb997
```
Packit 8cb997
Packit 8cb997
Packit 8cb997
Example playbook to ensure presence of host member certificate:
Packit 8cb997
Packit 8cb997
```yaml
Packit 8cb997
- name: Host present with certificate
Packit 8cb997
  hosts: ipaserver
Packit 8cb997
  become: true
Packit 8cb997
Packit 8cb997
  tasks:
Packit 8cb997
  - name: Host host01.example.com present with certificate
Packit 8cb997
    ipahost:
Packit Service 0f71a7
      ipaadmin_password: SomeADMINpassword
Packit 8cb997
      name: host01.example.com
Packit 8cb997
      certificate:
Packit 8cb997
      - MIIC/zCCAeegAwIBAg...
Packit 8cb997
      action: member
Packit 8cb997
```
Packit 8cb997
Packit 8cb997
Packit 8cb997
Example playbook to ensure presence of member managedby_host for serveral hosts:
Packit 8cb997
Packit 8cb997
```yaml
Packit 8cb997
---
Packit 8cb997
- name: Host present with managedby_host
Packit 8cb997
  hosts: ipaserver
Packit 8cb997
  become: true
Packit 8cb997
Packit 8cb997
  tasks:
Packit 8cb997
    ipahost:
Packit Service 0f71a7
      ipaadmin_password: SomeADMINpassword
Packit 8cb997
      hosts:
Packit 8cb997
      - name: host01.exmaple.com
Packit 8cb997
        managedby_host: server.exmaple.com
Packit 8cb997
      - name: host02.exmaple.com
Packit 8cb997
        managedby_host: server.exmaple.com
Packit 8cb997
      action: member
Packit 8cb997
```
Packit 8cb997
Packit 8cb997
Packit 8cb997
Example playbook to disable a host:
Packit 8cb997
Packit 8cb997
```yaml
Packit 8cb997
---
Packit 8cb997
- name: Playbook to handle hosts
Packit 8cb997
  hosts: ipaserver
Packit 8cb997
  become: true
Packit 8cb997
Packit 8cb997
  tasks:
Packit 8cb997
  # Ensure host is disabled
Packit 8cb997
  - ipahost:
Packit Service 0f71a7
      ipaadmin_password: SomeADMINpassword
Packit 8cb997
      name: host01.example.com
Packit 8cb997
      update_dns: yes
Packit 8cb997
      state: disabled
Packit 8cb997
```
Packit Service 0f71a7
`update_dns` controls if the DNS entries will be updated in this case. For `state` present it is controlling the update of the DNS SSHFP records, but not the the other DNS records.
Packit 8cb997
Packit 8cb997
Packit 8cb997
Example playbook to ensure a host is absent:
Packit 8cb997
Packit 8cb997
```yaml
Packit 8cb997
---
Packit 8cb997
- name: Playbook to handle hosts
Packit 8cb997
  hosts: ipaserver
Packit 8cb997
  become: true
Packit 8cb997
Packit 8cb997
  tasks:
Packit 8cb997
  # Ensure host is absent
Packit 8cb997
  - ipahost:
Packit 8cb997
      ipaadmin_password: password1
Packit 8cb997
      name: host01.example.com
Packit 8cb997
      state: absent
Packit 8cb997
```
Packit 8cb997
Packit 8cb997
Packit 8cb997
Variables
Packit 8cb997
=========
Packit 8cb997
Packit 8cb997
ipahost
Packit 8cb997
-------
Packit 8cb997
Packit 8cb997
Variable | Description | Required
Packit 8cb997
-------- | ----------- | --------
Packit 8cb997
`ipaadmin_principal` | The admin principal is a string and defaults to `admin` | no
Packit 8cb997
`ipaadmin_password` | The admin password is a string and is required if there is no admin ticket available on the node | no
Packit 8cb997
`name` \| `fqdn` | The list of host name strings. `name` with *host variables* or `hosts` containing *host variables* need to be used. | no
Packit 8cb997
**Host variables** | Only used with `name` variable in the first level. | no
Packit 8cb997
`hosts` | The list of host dicts. Each `hosts` dict entry can contain **host variables**.
There is one required option in the `hosts` dict:| no
Packit 8cb997
  | `name` \| `fqdn` - The user name string of the entry. | yes
Packit 8cb997
  | **Host variables** | no
Packit 8cb997
`update_password` |  Set password for a host in present state only on creation or always. It can be one of `always` or `on_create` and defaults to `always`. | no
Packit 8cb997
`action` | Work on host or member level. It can be on of `member` or `host` and defaults to `host`. | no
Packit 8cb997
`state` | The state to ensure. It can be one of `present`, `absent` or `disabled`, default: `present`. | yes
Packit 8cb997
Packit 8cb997
Packit 8cb997
**Host Variables:**
Packit 8cb997
Packit 8cb997
Variable | Description | Required
Packit 8cb997
-------- | ----------- | --------
Packit 8cb997
`description` | The host description. | no
Packit 8cb997
`locality` | Host locality (e.g. "Baltimore, MD"). | no
Packit 8cb997
`location` \| `ns_host_location` | Host location (e.g. "Lab 2"). | no
Packit 8cb997
`platform` \| `ns_hardware_platform` | Host hardware platform (e.g. "Lenovo T61"). | no
Packit 8cb997
`os` \| `ns_os_version` | Host operating system and version (e.g. "Fedora 9"). | no
Packit Service 0f71a7
`password` \| `user_password` \| `userpassword` | Password used in bulk enrollment for absent or not enrolled hosts. | no
Packit Service 0f71a7
`random` \| `random_password` |  Initiate the generation of a random password to be used in bulk enrollment for absent or not enrolled hosts. | no
Packit 8cb997
`certificate` \| `usercertificate` | List of base-64 encoded host certificates | no
Packit 8cb997
`managedby` \| `principalname` \| `krbprincipalname` | List of hosts that can manage this host | no
Packit 8cb997
`principal` \| `principalname` \| `krbprincipalname` | List of principal aliases for this host | no
Packit 8cb997
`allow_create_keytab_user` \| `ipaallowedtoperform_write_keys_user` | Users allowed to create a keytab of this host. | no
Packit 8cb997
`allow_create_keytab_group` \| `ipaallowedtoperform_write_keys_group` | Groups allowed to create a keytab of this host. | no
Packit 8cb997
`allow_create_keytab_host` \| `ipaallowedtoperform_write_keys_host` | Hosts allowed to create a keytab of this host. | no
Packit 8cb997
`allow_create_keytab_hostgroup` \| `ipaallowedtoperform_write_keys_hostgroup` | Host groups allowed to create a keytab of this host. | no
Packit 8cb997
`allow_retrieve_keytab_user` \| `ipaallowedtoperform_read_keys_user` | Users allowed to retieve a keytab of this host. | no
Packit 8cb997
`allow_retrieve_keytab_group` \| `ipaallowedtoperform_read_keys_group` | Groups allowed to retieve a keytab of this host. | no
Packit 8cb997
`allow_retrieve_keytab_host` \| `ipaallowedtoperform_read_keys_host` | Hosts allowed to retieve a keytab of this host. | no
Packit 8cb997
`allow_retrieve_keytab_hostgroup` \| `ipaallowedtoperform_read_keys_hostgroup` | Host groups allowed to retieve a keytab of this host. | no
Packit 8cb997
`mac_address` \| `macaddress` | List of hardware MAC addresses. | no
Packit 8cb997
`sshpubkey` \| `ipasshpubkey` | List of SSH public keys | no
Packit 8cb997
`userclass` \| `class` | Host category (semantics placed on this attribute are for local interpretation) | no
Packit Service 0f71a7
`auth_ind` \| `krbprincipalauthind` | Defines a whitelist for Authentication Indicators. Use 'otp' to allow OTP-based 2FA authentications. Use 'radius' to allow RADIUS-based 2FA authentications. Use empty string to reset auth_ind to the initial value. Other values may be used for custom configurations. choices: ["radius", "otp", "pkinit", "hardened", ""] | no
Packit 8cb997
`requires_pre_auth` \| `ipakrbrequirespreauth` | Pre-authentication is required for the service (bool) | no
Packit 8cb997
`ok_as_delegate` \| `ipakrbokasdelegate` | Client credentials may be delegated to the service (bool) | no
Packit 8cb997
`ok_to_auth_as_delegate` \| `ipakrboktoauthasdelegate` | The service is allowed to authenticate on behalf of a client (bool) | no
Packit 8cb997
`force` | Force host name even if not in DNS. | no
Packit 8cb997
`reverse` | Reverse DNS detection. | no
Packit Service 0f71a7
`ip_address` \| `ipaddress` | The host IP address list. It can contain IPv4 and IPv6 addresses. No conflict check for IP addresses is done. | no
Packit Service 0f71a7
`update_dns` | For existing hosts: DNS SSHFP records are updated with `state` present and all DNS entries for a host removed with `state` absent. | no
Packit 8cb997
Packit 8cb997
Packit 8cb997
Return Values
Packit 8cb997
=============
Packit 8cb997
Packit 8cb997
ipahost
Packit 8cb997
-------
Packit 8cb997
Packit 8cb997
There are only return values if one or more random passwords have been generated.
Packit 8cb997
Packit 8cb997
Variable | Description | Returned When
Packit 8cb997
-------- | ----------- | -------------
Packit 8cb997
`host` | Host dict with random password. (dict) 
Options: | If random is yes and host did not exist or update_password is yes
Packit 8cb997
  | `randompassword` - The generated random password | If only one host is handled by the module
Packit 8cb997
  | `name` - The host name of the host that got a new random password. (dict) 
Options:
  `randompassword` - The generated random password | If several hosts are handled by the module
Packit 8cb997
Packit 8cb997
Packit 8cb997
Authors
Packit 8cb997
=======
Packit 8cb997
Packit 8cb997
Thomas Woerner