aboutsummaryrefslogtreecommitdiff
path: root/changepw.yml
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2018-01-20 10:05:01 -0500
committerB Stack <bgstack15@gmail.com>2018-01-20 10:05:01 -0500
commitd337da41b882a701e6847fc7c2b12892862c5611 (patch)
tree72e7fb5e0c54e4fd905e8c222762910f08b16c52 /changepw.yml
downloadchangepw-d337da41b882a701e6847fc7c2b12892862c5611.tar.gz
changepw-d337da41b882a701e6847fc7c2b12892862c5611.tar.bz2
changepw-d337da41b882a701e6847fc7c2b12892862c5611.zip
initial commitHEADmaster
Diffstat (limited to 'changepw.yml')
-rw-r--r--changepw.yml71
1 files changed, 71 insertions, 0 deletions
diff --git a/changepw.yml b/changepw.yml
new file mode 100644
index 0000000..eafa847
--- /dev/null
+++ b/changepw.yml
@@ -0,0 +1,71 @@
+---
+# File: changepw.yml
+# Location: /etc/ansible/shell/changepw/
+# Author: bgstack15@gmail.com
+# Startdate: 2018-01-04
+# Title: Ansible Playbook that Changes My Password
+# Purpose: Make changing my password easy in an environment where hosts have expirable passwords
+# History:
+# Usage:
+# Use changepw.sh, which calls this playbook.
+# Reference:
+# ref/create_local_admin.yml
+# Improve:
+# Document:
+
+- name: Playbook that changes my password
+ vars_files:
+ - "{{ vaultfile }}"
+ hosts: "{{ sitelimit }}"
+ tasks:
+ - ping:
+
+ - name: Install dependencies on OL7
+ yum:
+ name: "{{ item }}"
+ enablerepo: ol7_latest
+ with_items:
+ - pexpect
+ when:
+ - ansible_distribution_major_version == "7"
+ - ansible_os_family == "RedHat"
+ tags:
+ - expect
+
+ - name: Learn if local user exists
+ shell: grep -o -e "^{{ thisuser }}:" /etc/passwd | cat -
+ register: user_stat
+ changed_when: false
+
+ - name: Set password only when local user exists
+ block:
+
+ - name: Set permanent password
+ expect:
+ command: passwd "{{ thisuser }}"
+ responses:
+ (?i)password: "{{ thispassword }}"
+ tags:
+ - expect
+
+ - name: Set password, hardcore mode
+ lineinfile:
+ path: /etc/shadow
+ regexp: '^({{ thisuser }}:)\$.{80,120}((:.+){6})'
+ backrefs: yes
+ line: '\1{{ thispasswordhash }}\2'
+ backup: yes
+ register: shadow
+ tags:
+ - hardcore
+
+ - name: Set password last date set to today
+ shell: chage -d "{{ ansible_date_time.date }}" "{{ thisuser }}"
+ changed_when: false
+ tags:
+ - hardcore
+
+ when:
+ - user_stat.stdout != ""
+ tags:
+ - changepw
bgstack15