From eb16cabd3429ade7e4f096573382b9554ff11525 Mon Sep 17 00:00:00 2001 From: Emmanouil Kampitakis Date: Sun, 17 Jun 2018 08:48:53 +0000 Subject: [PATCH] Extracted the basic role from the madonsible playbook --- .travis.yml | 29 ++++++++++++++ README.md | 38 +++++++++++++++++++ defaults/main.yml | 2 + files/etc/vim/vimrc | 0 files/public_keys/madonius | 1 + handlers/main.yml | 2 + meta/main.yml | 27 +++++++++++++ sample_user_definition.yml | 11 ++++++ tasks/apt.yml | 27 +++++++++++++ tasks/main.yml | 15 ++++++++ tasks/sudo.yml | 8 ++++ tasks/users.yml | 16 ++++++++ .../inventory/vagrant_ansible_inventory | 3 ++ tests/Vagrantfile | 10 +++++ tests/ansible.cfg | 2 + tests/inventory | 1 + tests/test.yml | 13 +++++++ vars/main.yml | 2 + 18 files changed, 207 insertions(+) create mode 100644 .travis.yml create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 files/etc/vim/vimrc create mode 100644 files/public_keys/madonius create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 sample_user_definition.yml create mode 100644 tasks/apt.yml create mode 100644 tasks/main.yml create mode 100644 tasks/sudo.yml create mode 100644 tasks/users.yml create mode 100644 tests/.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory create mode 100644 tests/Vagrantfile create mode 100644 tests/ansible.cfg create mode 100644 tests/inventory create mode 100644 tests/test.yml create mode 100644 vars/main.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..3c0617a --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +Basic role for all of madonius' home server +========= + +Does the basic stuff you expect a role to do + +Requirements +------------ + +This role expect the machine to be a debian machine. + +Role Variables +-------------- + +None + +Dependencies +------------ + +None + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +© Madonius 2016 diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..2a274ce --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for basic diff --git a/files/etc/vim/vimrc b/files/etc/vim/vimrc new file mode 100644 index 0000000..e69de29 diff --git a/files/public_keys/madonius b/files/public_keys/madonius new file mode 100644 index 0000000..6795f4e --- /dev/null +++ b/files/public_keys/madonius @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC/4K5CJyIeBlRO9La6Pm1ZAbjknW+VR1xLOA0QnHNLIecnSyCLS0Gr0xro+o3L4hX8XLDhmfu9LzV+Ih78C0LT2dISXwhnqPXu72QqlzOR/qsCHwhjt8x7tHL3jjLW/J85bljCq+JahyfgzneaoXw36QtHYObh1TFJVCGAivyh6Z/XYGIKqiecgO5r/hQM7UOwOnHmtw8YbowsaV+iQh5dIDjW0lpzx1tXuGi22xB/QXmA7bOEYRt50ZrMYFud2Sc7IlyKsYLahEEAhUPrXJ83ij7j71itnns09tTb6eBCpjFYzVlpTZfPWz1nNHTkOhfqg41+lBjQeDffH6ZvECnz madonius@Brorsen diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..f5945c9 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for basic diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..5ad02c7 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,27 @@ +galaxy_info: + author: Emmanouil Kampitakis + description: Base class for the home infrastructure + company: Hometech Hometechnologies for the Homes of homies + + license: GPLv3 + + min_ansible_version: 2.1 + + platforms: + - name: Debian + versions: + - all + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is + # a keyword that describes and categorizes the role. + # Users find roles by searching for tags. Be sure to + # remove the '[]' above if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of + # alphanumeric characters. Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. + # Be sure to remove the '[]' above if you add dependencies + # to this list. diff --git a/sample_user_definition.yml b/sample_user_definition.yml new file mode 100644 index 0000000..f1596c3 --- /dev/null +++ b/sample_user_definition.yml @@ -0,0 +1,11 @@ +users: + - name: madonius + ssh-key: dsa1024 hypersecurekey + uid: + shell: /bin/zsh + comment: + groups: + - sudo + - webadmin + - banana + diff --git a/tasks/apt.yml b/tasks/apt.yml new file mode 100644 index 0000000..58ece8f --- /dev/null +++ b/tasks/apt.yml @@ -0,0 +1,27 @@ +--- +- name: Update the installed packages + apt: + update_cache: yes + upgrade: yes + become: true + +- name: Install essential packages + package: + name: "{{ item }}" + state: present + become: true + with_items: + - vim + - emacs + - git + - htop + - zsh + - python + - python3 + - screen + - tmux + - dnsutils + - stow + - mosh + - fail2ban + - tig diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..8f19c17 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,15 @@ +--- +# tasks file for basic +- name: Make apt stuff + include: apt.yml + tags: + - apt + +- name: Configure users + include: users.yml + loop: "{{ basic_users }}" + loop_control: + loop_var: os_user + +- name: Setup sudo access + include: sudo.yml diff --git a/tasks/sudo.yml b/tasks/sudo.yml new file mode 100644 index 0000000..ceefccb --- /dev/null +++ b/tasks/sudo.yml @@ -0,0 +1,8 @@ +--- +- name: Give sudo group passwordless sudo + lineinfile: + dest: /etc/sudoers + regexp: "^%sudo" + line: "%sudo ALL=(ALL) NOPASSWD: ALL" + tags: sudo + become: true diff --git a/tasks/users.yml b/tasks/users.yml new file mode 100644 index 0000000..79bf03f --- /dev/null +++ b/tasks/users.yml @@ -0,0 +1,16 @@ +--- +- name: "Add user {{ os_user.name }}" + user: + name: "{{ os_user.name }}" + comment: "{{ os_user.comment }}" + uid: "{{ os_user.uid }}" + shell: "{{ os_user.shell }}" + groups: "{{ os_user.groups }}" + state: "{{ os_user.state }}" + become: true + +- name: Copy local ssh key to authorized keys file + authorized_key: + user: "{{ os_user.name }}" + key: "{{ os_user.ssh_auth_key }}" + become: true diff --git a/tests/.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory b/tests/.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory new file mode 100644 index 0000000..4b479a5 --- /dev/null +++ b/tests/.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory @@ -0,0 +1,3 @@ +# Generated by Vagrant + +default ansible_host=127.0.0.1 ansible_port=2222 ansible_user='vagrant' ansible_ssh_private_key_file='/home/madonius/.vagrant.d/insecure_private_key' diff --git a/tests/Vagrantfile b/tests/Vagrantfile new file mode 100644 index 0000000..c6a36d8 --- /dev/null +++ b/tests/Vagrantfile @@ -0,0 +1,10 @@ +Vagrant.configure(2) do |config| + config.vm.hostname = "vagrant.example.com" + config.vm.box = "debian/stretch64" + config.ssh.insert_key = false + + config.vm.provision "ansible" do |ansible| + ansible.verbose ="vv" + ansible.playbook = "test.yml" + end +end diff --git a/tests/ansible.cfg b/tests/ansible.cfg new file mode 100644 index 0000000..9496518 --- /dev/null +++ b/tests/ansible.cfg @@ -0,0 +1,2 @@ +[defaults] +roles_path=../../ diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..f51a54c --- /dev/null +++ b/tests/inventory @@ -0,0 +1 @@ +10.0.0.100 diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..952a855 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,13 @@ +--- +- hosts: all + roles: + - role: basic + basic_users: + - name: madonius + comment: 'madonius' + uid: 1337 + shell: /bin/zsh + groups: sudo + state: present + ssh_auth_key: > + ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB3HexVmU/vTVFUFk2AAB1h3mOOrfFPt1Gq2cBldaYnn madonius@iapeptus diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..1cfa44d --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for basic