Создание списка локальных пользователей с использованием AnsibleLinux

Anonymous
Создание списка локальных пользователей с использованием Ansible

Сообщение Anonymous »

Я погуглил сценарий, чтобы получить список локальных учетных записей пользователей на моем предприятии, и мне дали это: < /p>

Код: Выделить всё

---
- name: Gather local user accounts
hosts: all
gather_facts: false # No need for extensive facts gathering for this task

tasks:
- name: Get local user information
ansible.builtin.getent:
database: passwd
register: passwd_entries

- name: Process user data and store in a variable
ansible.builtin.set_fact:
local_users: |
{% set user_list = [] %}
{% for user, details in passwd_entries.passwd.items() %}
{% if details[6] != '/usr/sbin/nologin' and details[6] != '/bin/false' %}
{% set user_info = {
'username': user,
'uid': details[2],
'gid': details[3],
'home_directory': details[5],
'shell': details[6]
} %}
{% set _ = user_list.append(user_info) %}
{% endif %}
{% endfor %}
{{ user_list | to_nice_json }}

- name: Create a summary document of local users
hosts: localhost # Run this part on the Ansible control node
connection: local
gather_facts: false

tasks:
- name: Create local users report file
ansible.builtin.copy:
content: |
Local User Accounts Report

{% for host in ansible_play_batch %}
--- Host: {{ hostvars[host].ansible_hostname }} ---
{% if hostvars[host].local_users is defined %}
{{ hostvars[host].local_users | from_json | to_nice_yaml }}
{% else %}
No local user information found.
{% endif %}
{% endfor %}
dest: "./local_users_report.txt" # Output file path
run_once: true # Ensure the file is created only once
< /code>
Я получаю синтаксисную ошибку (найденный символ, который не может запустить ни один токен) в строке 28, которая выглядит так: < /p>
{% endfor %}
^ here
< /code>
Когда я перемещаю его в 3 пространства, он очищается, но затем я получаю: < /p>
- name: create a summary document of local users
^ here
с ошибкой "не может найти ожидаемого ':'
Любая помощь будет оценена!

Подробнее здесь: https://stackoverflow.com/questions/797 ... ng-ansible

Вернуться в «Linux»