Ansible create user: was not created by default .bashrc?

I create users with these tasks:

- name: ensure home directory
  sudo: yes
  file: path={{item.home}} state=directory
  with_items: users

- name: create user {{item.name}}
  sudo: yes
  user: name={{item.name}} home={{item.home}} shell=/bin/bash group={{item.group}} groups={{item.groups}} password={{item.password}} state=present
  with_items: users

but it seems that ~ / .bashrc per user is not created in their home directory.

Is there a way to create a default .bashrc base file?

thanks

+4
source share
3 answers

I used a specific path for home folders (other than traditional / home / user folders): /specific/path/home/user1

Since I had an error that the path /specific/path/home/user1could not be created when creating user1, I created the home folders before creating the users. However, if the home folder already exists when the user is created, it is .bashrcnot copied by default .

+1
source

Ansible 2.0, skeleton:

. createhome!

:

- name: "Create deployment user"
  user:
    name: "foobar"
    groups: "sudo"
    append: yes
    skeleton: "/etc/skel"
    createhome: yes
+1

You need to add append=yesat the end of the user command User:

- name: Add users
  add_user:
    name: '{{item.name}}'
    home: '{{item.home}}'
    shell: /bin/bash
    group: '{{item.group}}'
    groups: '{{item.groups}}'
    password: '{{item.password}}'
    state: present
    append: yes 
with_items: users
0
source

Source: https://habr.com/ru/post/1524914/


All Articles