From 5cc2c776df496cfc788695390bfb3527b44852c4 Mon Sep 17 00:00:00 2001 From: Vladimir Blando Date: Wed, 15 Apr 2020 03:10:30 +0800 Subject: [PATCH] Initial commit for create user role Change-Id: I8b4f03df4936e4ba6a1abf099fa099ad85cfc073 --- .gitignore | 1 + .yamllint | 5 +++++ .zuul.yaml | 40 ++++++++++++++++++++++++++++++++++++++++ README.rst | 1 + defaults/main.yml | 17 +++++++++++++++++ examples/playbook.yml | 27 +++++++++++++++++++++++++++ tasks/main.yml | 38 ++++++++++++++++++++++++++++++++++++++ test-requirements.txt | 2 ++ tox.ini | 10 ++++++++++ 9 files changed, 141 insertions(+) create mode 100644 .gitignore create mode 100644 .yamllint create mode 100644 .zuul.yaml create mode 100644 README.rst create mode 100644 defaults/main.yml create mode 100644 examples/playbook.yml create mode 100644 tasks/main.yml create mode 100644 test-requirements.txt create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..172bf57 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.tox diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..347860c --- /dev/null +++ b/.yamllint @@ -0,0 +1,5 @@ +--- +extends: default + +ignore: | + .tox diff --git a/.zuul.yaml b/.zuul.yaml new file mode 100644 index 0000000..42f3905 --- /dev/null +++ b/.zuul.yaml @@ -0,0 +1,40 @@ +--- +# Copyright 2020 VEXXHOST, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- job: + name: ansible-role-base-server-functional + run: examples/playbook.yml + +- job: + name: ansible-role-base-server-functional-centos-7 + parent: ansible-role-base-server-functional + nodeset: centos-7 + +- job: + name: ansible-role-base-server-functional-debian-buster + parent: ansible-role-base-server-functional + nodeset: debian-buster + +- project: + check: + jobs: + - ansible-role-base-server-functional-centos-7 + - ansible-role-base-server-functional-debian-buster + - tox-linters + gate: + jobs: + - ansible-role-base-server-functional-centos-7 + - ansible-role-base-server-functional-debian-buster + - tox-linters diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..a1506c3 --- /dev/null +++ b/README.rst @@ -0,0 +1 @@ +Ansible Role Base Server diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..c1da392 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,17 @@ +--- +# Copyright 2020 VEXXHOST, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +base_server_groups: [] +base_server_users: [] diff --git a/examples/playbook.yml b/examples/playbook.yml new file mode 100644 index 0000000..169a44f --- /dev/null +++ b/examples/playbook.yml @@ -0,0 +1,27 @@ +--- +# Copyright 2020 VEXXHOST, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +- name: Run base-server + hosts: all + roles: + - base-server + vars: + base_server_users: + - name: "vblando" + groups: ['sysadmin'] + shell: "/bin/bash" + state: "present" + public_key: "https://github.com/vblando.keys" + base_server_groups: + - sysadmin diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..eab0385 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,38 @@ +--- +# Copyright 2020 VEXXHOST, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: Create groups + group: + name: "{{ item }}" + state: present + become: true + loop: "{{ base_server_groups }}" + +- name: Create users + user: + name: "{{ item.name }}" + groups: "{{ item.groups }}" + shell: "{{ item.shell | default('/bin/bash') }}" + state: "{{ item.state | default(omit) }}" + become: true + with_items: "{{ base_server_users }}" + +- name: Setup authorized keys + authorized_key: + user: "{{ item.name }}" + key: "{{ item.public_key }}" + state: "{{ item.state | default(omit) }}" + become: true + with_items: "{{ base_server_users }}" diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..4c2b5be --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,2 @@ +ansible-lint +yamllint diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..6732e8e --- /dev/null +++ b/tox.ini @@ -0,0 +1,10 @@ +[tox] +minversion = 2.0 +skipsdist = True + +[testenv:linters] +deps = + -rtest-requirements.txt +commands = + yamllint {toxinidir} + ansible-lint examples/playbook.yml .