# Installing NIS package with ansible

**URL:** <https://forum.ansible.com/t/installing-nis-package-with-ansible/6730>\
**Category:** Get Help\
**Created:** [June 23, 2024, 6:03pm UTC](https://forum.ansible.com/t/installing-nis-package-with-ansible/6730 "2024-06-23T18:03:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DetectiveObvious](https://avatars.discourse-cdn.com/v4/letter/d/c4cdca/32.png) [@DetectiveObvious](https://forum.ansible.com/u/DetectiveObvious)\
**Post date:** [June 23, 2024, 6:03pm UTC](https://forum.ansible.com/t/installing-nis-package-with-ansible/6730/1 "2024-06-23T18:03:53Z")

</div>

Hi, I’m trying to install NIS package using ansible apt. When package is installed manually, it asks to put name of the cluster. I want to do this automatically, so I found it is saved in file /etc/defaultdomain.  
My workaround:

```auto
- name: install nis package and change domain to CLUSTER_NAME
      block:
        - name: install
          package:
            name: nis
        - name: change domain
          lineinfile:
            path: /etc/defaultdomain
            regexp: '.*'
            state: present
            line: 'CLUSTER_NAME'

```

Is there a way to make it better?

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [June 24, 2024, 8:35am UTC](https://forum.ansible.com/t/installing-nis-package-with-ansible/6730/2 "2024-06-24T08:35:20Z")

</div>

There doesn’t appear to be any [debconf](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/debconf_module.html) options that can be set for the [Debian package](https://packages.debian.org/bookworm/nis), however it also doesn’t contain a `/etc/defaultdomain` file so perhaps you are using a different distro / package?

```bash
apt-file list nis
nis: /etc/default/nis                     
nis: /usr/share/doc/nis/NEWS.Debian.gz
nis: /usr/share/doc/nis/changelog.gz
nis: /usr/share/doc/nis/copyright
nis: /usr/share/doc/nis/nis.debian.howto.gz
nis: /usr/share/lintian/overrides/nis

```

---

<div class="post-metadata">

**Author:** ![DetectiveObvious](https://avatars.discourse-cdn.com/v4/letter/d/c4cdca/32.png) [@DetectiveObvious](https://forum.ansible.com/u/DetectiveObvious)\
**Post date:** [June 24, 2024, 4:00pm UTC](https://forum.ansible.com/t/installing-nis-package-with-ansible/6730/3 "2024-06-24T16:00:44Z")

</div>

Forgot to mention. I’m using Ubuntu 20.04 LTS. Mention of /etc/defaultdomain I have found here - [SettingUpNISHowTo - Community Help Wiki](https://help.ubuntu.com/community/SettingUpNISHowTo).

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [June 24, 2024, 4:20pm UTC](https://forum.ansible.com/t/installing-nis-package-with-ansible/6730/4 "2024-06-24T16:20:24Z")

</div>

The [Ubuntu package](https://packages.ubuntu.com/noble/nis) appears to be the same as [the Debian one](https://packages.debian.org/bookworm/nis), so I expect it also doesn’t have any debconf options so you will need to write Ansible tasks to generate / edit the configuration as required.

---

<div class="post-metadata">

**Author:** ![Thulium-Drake](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/thulium-drake/32/833_2.png) [@Thulium-Drake](https://forum.ansible.com/u/Thulium-Drake)\
**Post date:** [July 1, 2024, 10:03pm UTC](https://forum.ansible.com/t/installing-nis-package-with-ansible/6730/5 "2024-07-01T22:03:23Z")

</div>

I’d suggest that you template the NIS config files, that’s the only way to make sure that they will fully conform to what you’re expecting. When writing code I only use `lineinfile` when either not the whole file is under my control (and then still prefer `blockinfile`), or it’s massive and you really only need to change a single line in it.

Then it’d look like this:

```auto
- name: 'Ensure NIS packages'
  ansible.builtin.package:
    name: 'nis'
    state: 'present'

- name: 'Ensure defaultdomain'
  ansible.builtin.template:
    src: 'files/nis/defaultdomain.j2' # translates to <playbooks>/files/nis/defaultdomain.j2
    dest: '/etc/defaultdomain'
    owner: 'root'
    group: 'root'
    mode: '0644' # not sure, been a while since I've seen a working NIS server

```

And your template would look like:

```auto
# {{ ansible_managed }}
<whatever config you need, as I mentioned, it's been a while since I've touched NIS ;-)>

```

This will make sure that whatever happens, this file will always be _exactly_ what you need it to be.

The only thing that can still happen is that the config file itself can become incompatible with NIS (though, I don’t see that happening anymore). Which means you’ll need to update your Ansible code (which in turn will fix it on _all_ the systems that you have that run NIS.

Have fun! 😉
