exam 1

 

Add an entry for node00 in ~/playbooks/inventory file. IP address of node00 host is 172.20.1.100 and SSH user and password is root and Passw0rd. We have a list of users in ~/playbooks/data/users.yml file. There are two groups in there admins and developers which have list of different users. Create a playbook ~/playbooks/add_users.yml to perform below given tasks on node00 node:


a. Add all users given in users.yml on node00.

b. Make sure home directory for all users under developers group is /var/www and for admins it should be default.

c. Set password d3v3l0p3r for all users under developers group and adm$n$ for users under admins group. Make sure to use Ansible vault to encrypt the passwords, use ~/playbooks/secrets/vault.txt file as vault secret file.

d. All users under admins group must be added as sudo user, for that simply make them member of wheel group on node00

=============================

========================================

=======================================================

Update inventory as per below given code
node00 ansible_host=172.20.1.100 ansible_user=root ansible_ssh_pass=Passw0rd
node01 ansible_host=172.20.1.101 ansible_user=root ansible_ssh_pass=Passw0rd
node02 ansible_host=172.20.1.102 ansible_user=root ansible_ssh_pass=Passw0rd
Create vault password for admins and developers
ansible-vault encrypt_string d3v3l0p3r
ansible-vault encrypt_string  adm$n$
Create add_users.yml playbook and add below given code
---
- hosts: node00
  gather_facts: no
  vars:
    admin_pass: !vault |
          $ANSIBLE_VAULT;1.1;AES256
          64396331383031323064343432353935323334626437666531313633343232353936323738313337
          3436666266356534343934653132363866626231636663610a663731653135316132613831323463
          61663331626236303163306234353632643231353036323833373865346531306331613761356665
          3365653631656530310a626332643537333861653335643836646566323934653362333364386137
          3731
    developer_pass: !vault |
          $ANSIBLE_VAULT;1.1;AES256
          63613761313339646563643435326633313066303030666266393232646137343065376530363933
          3034353231653239656332363661346337353836666130370a613366646565373431343932633337
          34666430376264386137326632626637383630383262333330376661656266393665386337326465
          3165366632623865660a363866653237386163653636373764626334303631333062623762396235
          6630
  tasks:
    - name: Include user.yml
      include_vars:
        file: data/users.yml
    - name: Creating admins
      user:
        name: "{{ item }}"
        password: "{{ admin_pass | string | password_hash('sha512') }}"
        groups: wheel
      with_items: "{{ admins | list }}"

    - name: creating developers
      user:
        name: "{{ item }}"
        password: "{{ developer_pass | string | password_hash('sha512') }}"
        home: /var/www
      with_items: "{{ developers | list }}"

Comments

Popular posts from this blog

exam 16

ansible 5

practical 3