Created
June 5, 2014 02:26
-
-
Save pipitone/8193718a7ac2c0cbe713 to your computer and use it in GitHub Desktop.
Ansible playbook replacement for NIS :-)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: YP | |
hosts: nis_slave:nis_client | |
sudo: yes | |
vars: | |
- min_uid: 1000 | |
- min_gid: 1000 | |
- nis_master: "{{groups['nis_master'][0]}}" | |
tasks: | |
# Basic idea here is we do things in two steps: | |
# 1. We grab the contents of the relevant file | |
# 2. We go line-by-line and ensure those lines are in the host's | |
# file. Use "regexp" to match the user/group name | |
# | |
- name: grab hosts | |
command: cat /etc/hosts | |
delegate_to: "{{nis_master}}" | |
register: etc_hosts | |
changed_when: False # b/c it's *always* changed | |
- name: grab passwd | |
command: cat /etc/passwd | |
delegate_to: "{{nis_master}}" | |
register: etc_passwd | |
changed_when: False # b/c it's *always* changed | |
- name: grab groups | |
command: cat /etc/group | |
delegate_to: "{{nis_master}}" | |
register: etc_group | |
changed_when: False # b/c it's *always* changed | |
- name: grab shadow | |
shell: 'awk -F: ''$3>{{min_uid}}{ printf("^%s\n",$1) }'' /etc/passwd | grep -f- /etc/shadow' | |
delegate_to: "{{nis_master}}" | |
register: etc_shadow | |
changed_when: False # it's *always* changed | |
- name: ensure hosts are present | |
lineinfile: dest=/etc/hosts | |
regexp='^{{item.split(" ").0}} ' | |
line="{{item}}" | |
owner=root group=root mode=0644 | |
when: item | search("^172.25") | |
with_items: etc_hosts.stdout_lines | |
- name: ensure users are present | |
lineinfile: dest=/etc/passwd | |
regexp='^{{item.split(":").0}}:' | |
line="{{item}}" | |
owner=root group=root mode=0644 | |
when: item.split(':').2|int > min_uid | |
with_items: etc_passwd.stdout_lines | |
- name: ensure groups are present | |
lineinfile: dest=/etc/group | |
regexp='^{{item.split(":").0}}:' | |
line="{{item}}" | |
owner=root group=root mode=0644 | |
when: item.split(':').2|int > min_gid | |
with_items: etc_group.stdout_lines | |
- name: ensure shadows are present | |
lineinfile: dest=/etc/shadow | |
regexp='^{{item.split(":").0}}:' | |
line="{{item}}" | |
owner=root group=root mode=0644 | |
with_items: etc_shadow.stdout_lines | |
tags: | |
- yp | |
- users |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment