blob: eafa847a60f64fbc8d7810041f1f23c0586444a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
|