目录结构如下
project
-- configure_login_defs.yml //脚本配置文件
-- inventory //服务器目录
-- host //服务器信息
脚本文件 configure_login_defs
---
- name: Configure /etc/login.defs
hosts: server
become: yes
tasks:
- name: Ensure PASS_MAX_DAYS is set to 90
lineinfile:
path: /etc/login.defs
regexp: '^#?PASS_MAX_DAYS'
line: 'PASS_MAX_DAYS 90'
- name: Ensure PASS_MIN_DAYS is set to 2
lineinfile:
path: /etc/login.defs
regexp: '^#?PASS_MIN_DAYS'
line: 'PASS_MIN_DAYS 2'
- name: Ensure PASS_MIN_LEN is set to 8
lineinfile:
path: /etc/login.defs
regexp: '^#?PASS_MIN_LEN'
line: 'PASS_MIN_LEN 8'
- name: Ensure PASS_WARN_AGE is set to 7
lineinfile:
path: /etc/login.defs
regexp: '^#?PASS_WARN_AGE'
line: 'PASS_WARN_AGE 7'
host ip配置文件
[server]
web100 ansible_host=10.0.0.100 ansible_user=hdt ansible_ssh_pass='xxx!@#'
web101 ansible_host=10.0.0.101 ansible_user=hdt ansible_ssh_pass='xxx!@#'
执行命令
ansible-playbook -i inventory/hosts configure_login_defs.yml