ansibleguy.linux_users

Rola Ansible - Użytkownicy i Grupy Systemowe

Rola Ansible do wdrażania użytkowników i grup na serwerach linux.

Testowano na:

  • Debian 11

Instalacja

# najnowsza wersja
ansible-galaxy role install git+https://github.com/ansibleguy/linux_users

# z ansible galaxy
ansible-galaxy install ansibleguy.linux_users

# lub do niestandardowej ścieżki ról
ansible-galaxy install ansibleguy.linux_users --roles-path ./roles

# instalacja zależności
ansible-galaxy install -r requirements.yml
python3 -m pip install -r requirements.txt

Użycie

Chcesz prosty interfejs graficzny Ansible? Sprawdź Ansible WebUI

Konfiguracja

Zdefiniuj konfigurację system_auth zgodnie z potrzebami:

system_auth:
  users:
    guy:
      comment: 'AnsibleGuy'
      password: !vault |
        $ANSIBLE_VAULT;1.1;AES256
        TWOJE ZASZYFROWANE HASŁO
      ssh_pub:
        - 'klucz_ssh'
      privileges:
        - '/usr/bin/rsync'
        - '/bin/systemctl restart apache2.service'
  
    other_guy:
      comment: 'Niezwykły użytkownik'
      shell: '/bin/fancyshell'
      always_update_password: true
      password: !vault |
        $ANSIBLE_VAULT;1.1;AES256
        TWOJE ZASZYFROWANE HASŁO
      ssh_pub:
        - 'klucz_ssh'
      scope: 'dc_europe_west'
      privileges:
        - '/bin/systemctl restart some_service.service'
      sudoers_prompt: true
  
    root:
      dont_touch: true
      bash_aliases:
        ll: 'ls -l'
  
  groups:
    ag_guest:
      members: ['joe', 'who?']
    ag_tester:
      members: ['hans']
    ag_users:
      members: ['lisa']
      nested_groups: ['ag_tester']
    ag_superguys:
      members: ['seppal']
      parents: ['ag_users']
    ag_devops:
      members: ['luis']
    ag_admins:
      members: ['reymond']
      member_of: ['ag_superguys']

Możesz użyć 'ansible-vault', aby zaszyfrować swoje hasła:

ansible-vault encrypt_string

Wykonanie

Uruchom playbook:

ansible-playbook -K -D -i inventory/hosts.yml playbook.yml --ask-vault-pass

Grupy Zagnieżdżone

Możesz powiązać dwie grupy i pozwolić im dziedziczyć członków.

Jeśli inna grupa powinna dziedziczyć wszystkich członków aktualnej:

  • member_of
  • parents

Jeśli aktualna grupa powinna dziedziczyć wszystkich członków innej:

  • nested_groups
  • children

Funkcjonalność

  • Użytkownicy

    • Ograniczenie użytkownika => ograniczenie serwerów, na których użytkownik powinien być utworzony
    • Uprawnienia sudo dla określonych poleceń
    • Klucze SSH
    • Ustawienie aliasów Bash
  • Grupy

    • zagnieżdżone grupy (dziedziczenie członków)

Informacje

  • Uwaga: ta rola obecnie wspiera tylko systemy oparte na Debianie

  • Uwaga: Większość funkcjonalności roli można włączyć lub wyłączyć.

    Aby zobaczyć dostępne opcje - zapoznaj się z domyślną konfiguracją znajdującą się w głównym pliku domyślnym!

  • Ostrzeżenie: Nie każda ustawiona zmienna będzie sprawdzana pod kątem poprawności. Zła konfiguracja może złamać rolę!


Przykład

Konfiguracja

system_auth:
  users:
    guy:
      comment: 'AnsibleGuy'
      password: !vault |
        $ANSIBLE_VAULT;1.1;AES256
        TWOJE ZASZYFROWANE HASŁO
      ssh_pub:
        - 'klucz_ssh'
      privileges:
        - '/usr/bin/rsync'
        - '/bin/systemctl restart apache2.service'
  
    other_guy:
      comment: 'Niezwykły użytkownik'
      scope: 'dc_europe_west'
      remove: true
      force_remove: true
  
    another_guy:
      comment: 'Miły facet'
      password: !vault |
            $ANSIBLE_VAULT;1.1;AES256
            TWOJE ZASZYFROWANE HASŁO
      ssh_pub:
        - 'klucz_ssh'
      force_password_change: true
  
  groups:
    ag_guest:
      members: []
    ag_tester:
      members: ['other_guy', 'another_guy']
      state: 'absent'
    ag_users:
      members: []
      nested_group: ['ag_tester']
    ag_superguys:
      members: []
      parents: ['ag_users']
    ag_devops:
      members: []
    ag_admins:
      members: ['guy']
      member_of: ['ag_superguys']

Wynik:

guy@ansible:~# cat /etc/group
> ...
> ag_guest:x:1000:
> ag_users:x:1002:guy,another_guy
> ag_superguys:x:1003:guy
> ag_devops:x:1004:
> ag_admins:x:1005:guy
> guy:x:1006:
> another_guy:x:1007:

guy@ansible:~# cat /etc/passwd
> ...
> guy:x:1000:1006:Ansible managed - AnsibleGuy:/home/guy:/bin/bash
> another_guy:x:1001:1007:Ansible managed - Miły facet:/home/another_guy:/bin/bash

guy@ansible:~# cat /etc/sudoers.d/user_priv_guy 
> # Ansible managed
> 
> Cmnd_Alias USER_PRIV_GUY = \
>   /usr/bin/rsync, \
>   /bin/systemctl restart apache2.service
> 
> guy ALL=(ALL) NOPASSWD: USER_PRIV_GUY

guy@ansible:~# cat /etc/sudoers.d/user_priv_another_guy 
> # Ansible managed
> 
> Cmnd_Alias USER_PRIV_ANOTHERGUY = \
>   /bin/systemctl restart myNiceStuff.service
> 
> another_guy ALL=(ALL) USER_PRIV_ANOTHERGUY
O projekcie

Role to configure users and groups on a linux machine

Zainstaluj
ansible-galaxy install ansibleguy.linux_users
Licencja
other
Pobrania
2.6k
Właściciel
[email protected] | GPG: https://badges.ansibleguy.net/public.gpg