Creating a user

The final part of the common role is to add a user called lamp and add our public key to the user. Before we look at the task, let's look at the variable we will be using, which is defined in roles/common/defaults/main.yml:

users:  - { name: "lamp", group: "lamp", state: "present", key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}" }

As you can see, we are providing three bits of information:

  • name: This is the name of the user we want to create
  • group: This is the group we want to add our user to
  • state: If we want the user to be present or absent
  • key: Here, we are using an Ansible lookup task to read the content of the file at ~/.ssh/id_rsa.pub and use that as the value

The task in the roles/common/tasks/main.yml file for creating ...

Get Learn Ansible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.