|
| 1 | +(batch-users)= |
| 2 | + |
| 3 | +# Creating users in batches |
| 4 | + |
| 5 | +The {ref}`install-users` section details how to create the initial list of users. |
| 6 | + |
| 7 | +However in some cases it is useful to have a more automated way to create (and delete) users |
| 8 | +in batches. For example when preparing and cleaning up a group of students at the beginning and end of a semester. |
| 9 | + |
| 10 | +This section details how to create users defined in a CSV file using Ansible Playbooks. |
| 11 | + |
| 12 | +## Creating the CSV File |
| 13 | + |
| 14 | +Create the `student.csv` file which should contain the `username`, `password` and `group` columns. |
| 15 | + |
| 16 | +Here is an example of such file: |
| 17 | + |
| 18 | +```text |
| 19 | +username,password,group |
| 20 | +stu-megm1-01,bn3r7RjtOyg15X,megm1 |
| 21 | +stu-megm1-02,2shgP3xK7aTuMN,megm1 |
| 22 | +stu-megm1-03,Kh5jn4GuEIFIzY,megm1 |
| 23 | +stu-megm1-04,g9gBHQjJ4VqQG1,megm1 |
| 24 | +stu-megm1-05,73O88oFb6B1TB0,megm1 |
| 25 | +stu-megm1-06,laZubrmgKBNg1x,megm1 |
| 26 | +stu-megm1-07,gAONEMsgdz28si,megm1 |
| 27 | +stu-megm1-08,tjlGadyELWj59M,megm1 |
| 28 | +stu-megm1-09,soIb4txJDPjo1d,megm1 |
| 29 | +stu-megm1-10,QjhalcW9Uq5wxo,megm1 |
| 30 | +``` |
| 31 | + |
| 32 | +````{warning} |
| 33 | +Since the fields in the CSV file are delimited by commas, passwords should not contain any `,` character. |
| 34 | +```` |
| 35 | + |
| 36 | +## Running the playbooks |
| 37 | + |
| 38 | +To create the users, go to the `ansible/` folder and run the `student-create.yml` playbook with: |
| 39 | + |
| 40 | +```sh |
| 41 | +ansible-playbook student-create.yml -u ubuntu -e "studentdef=students.csv" |
| 42 | +``` |
| 43 | + |
| 44 | +It is also possible to delete the users from the same CSV definition, using the `student-remove.yml` playbook: |
| 45 | + |
| 46 | +```sh |
| 47 | +ansible-playbook student-remove.yml -u ubuntu -e "studentdef=students.csv" |
| 48 | +``` |
| 49 | + |
| 50 | +````{note} |
| 51 | +It is possible to pass additional parameters when creating users in batches. |
| 52 | +
|
| 53 | +For example if you have a file defining disk quotas for a group of students: |
| 54 | +
|
| 55 | +```yaml |
| 56 | +# default quotas for students |
| 57 | +quota: |
| 58 | + soft: 200G |
| 59 | + hard: 250G |
| 60 | +``` |
| 61 | +
|
| 62 | +You can run the playbook and reference that extra file: |
| 63 | +
|
| 64 | +```bash |
| 65 | +ansible-playbook student-create.yml -u ubuntu -e "studentdef=students.csv" -e @students-config.yml |
| 66 | +``` |
| 67 | +```` |
0 commit comments