Bohdan Blyzniuk
Bohdan Blyzniuk

Reputation: 634

Create ubuntu user on instance launch ansible aws

I am using ansible to launch aws instance. There is a default user on aws instance called "ubuntu" and I need to setup new user. Here is a guide to setup user manually, but is there any way to do it automatically via ansible?

Upvotes: 1

Views: 576

Answers (2)

Carlos Alves
Carlos Alves

Reputation: 46

Here's another version, with this one you avoid using the shell module and instead use the native user module, the same thing for authorized_keys

---
- hosts: "{{ host_name }}"
  become: yes
  become_method: sudo
  tasks:
  - name: Create user deploy
    user: name=deploy comment="The Deploy user" group=admin shell=/bin/bash
  - name: Copy deploy's authorized_keys file
    authorized_key: user=deploy key="your_authorized_key_file_name"

Upvotes: 3

Yaron Idan
Yaron Idan

Reputation: 6765

Here's an example playbook I wrote that does exactly that -

---
- hosts: "{{ host_name }}"
  become: yes
  become_method: sudo
  tasks:
  - name: Create user deploy
    shell: "adduser --disabled-password --gecos \"\" deploy10"
...

If need be, you can create a password user with slight changes to this playbook, and insert the authorized_keys part into this playbook. If you need any help with doing this let me know.

Upvotes: 0

Related Questions