From f138dc122eb614e26006232a7eb8700dcbc0a5a7 Mon Sep 17 00:00:00 2001 From: vincent Date: Mon, 8 Apr 2019 23:09:14 +0200 Subject: [PATCH 1/5] complete variable for autofs --- tasks/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index 2c7d903..b23ebf1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -19,6 +19,7 @@ system: no # not required. When creating an account C(state=present), setting this to C(yes) makes the user a system account. This setting cannot be changed on existing users. state: present # not required. choices: absent;present. Whether the account should exist or not, taking action if the state is different from what is stated. ssh_key_file: .ssh/id_rsa # not required. Optionally specify the SSH key filename. If this is a relative filename then it will be relative to the user's home directory. + uid: 1024 - name : set sudoers right lineinfile: @@ -33,7 +34,7 @@ validate: 'visudo -cf "%s"' with_items: - regexp: '^%{{username}}\s' - line: '%{{username}} ALL = (ALL) ALL' + line: '%{{username}} ALL = (ALL) NOPASSWD:ALL' - name: Ensure /etc/sudoers includes /etc/sudoers.d From 88d00fe24a7ddc00541a68e45f402eb37b1c6584 Mon Sep 17 00:00:00 2001 From: vincent Date: Tue, 9 Apr 2019 16:34:35 +0200 Subject: [PATCH 2/5] improve bootstrap --- handlers/main.yml | 5 ++++- tasks/main.yml | 14 +++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 11155a9..2114711 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,2 +1,5 @@ --- -# handlers file for ansible_bootstrap \ No newline at end of file +# handlers file for ansible_bootstrap + + - name: restart ssh + service: name=sshd state=restarted \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index b23ebf1..a46fb5d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,8 +1,8 @@ --- # tasks file for ansible_bootstrap -- name: "install python" - raw: pacman -Sy python --noconfirm +- name: "install python and archlinux-keyring" + raw: pacman -Sy python archlinux-keyring --noconfirm - name: sudoers install pacman: @@ -56,4 +56,12 @@ owner: "{{username}}" # not required. Name of the user that should own the file/directory, as would be fed to I(chown). with_items: - id_rsa - - authorized_keys \ No newline at end of file + - authorized_keys + +- name: Remove root SSH access + lineinfile: + dest: /etc/ssh/sshd_config + regexp: "^PermitRootLogin" + line: "PermitRootLogin no" + state: present + notify: restart ssh \ No newline at end of file From 36bb8799221f596bf6674be5d4fbef30c8931463 Mon Sep 17 00:00:00 2001 From: vincent Date: Wed, 10 Apr 2019 20:27:12 +0200 Subject: [PATCH 3/5] fix issue --- tasks/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tasks/main.yml b/tasks/main.yml index a46fb5d..8251672 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -20,6 +20,7 @@ state: present # not required. choices: absent;present. Whether the account should exist or not, taking action if the state is different from what is stated. ssh_key_file: .ssh/id_rsa # not required. Optionally specify the SSH key filename. If this is a relative filename then it will be relative to the user's home directory. uid: 1024 + shell: /bin/bash - name : set sudoers right lineinfile: From b533d3c87ea7b6c2839d5d496b081337dd3f8c91 Mon Sep 17 00:00:00 2001 From: vincent Date: Thu, 11 Apr 2019 18:53:38 +0200 Subject: [PATCH 4/5] change variable username --- defaults/main.yml | 4 +++- tasks/main.yml | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 4f5cb58..891da30 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,4 +1,6 @@ --- # defaults file for ansible_bootstrap -username: vincent +user: + name: vincent + uid: 1024 userPassword: $6$GX8Mnp13vKWc1rye$HnFNZ/9oUg8K1rkaHJ1DKKk6IvWP0NP8K/dPOtLOfWjoVmQtx8MiF6eMEVJqjLZvCckDkg9AHjQzwQZfFGzED0 \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index 8251672..08d36a4 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -12,19 +12,19 @@ - name: create profil user: - name: "{{username}}" # required. Name of the user to create, remove or modify. + name: "{{user.name}}" # required. Name of the user to create, remove or modify. skeleton: false # not required. Optionally set a home skeleton directory. Requires create_home option! create_home: yes # not required. Unless set to C(no), a home directory will be made for the user when the account is created or if the home directory does not exist.,Changed from C(createhome) to C(create_home) in version 2.5. password: "{{userPassword}}" # not required. Optionally set the user's password to this crypted value.,On macOS systems, this value has to be cleartext. Beware of security issues.,See U(https://docs.ansible.com/ansible/faq.html#how-do-i-generate-crypted-passwords-for-the-user-module) for details on various ways to generate these password values. system: no # not required. When creating an account C(state=present), setting this to C(yes) makes the user a system account. This setting cannot be changed on existing users. state: present # not required. choices: absent;present. Whether the account should exist or not, taking action if the state is different from what is stated. ssh_key_file: .ssh/id_rsa # not required. Optionally specify the SSH key filename. If this is a relative filename then it will be relative to the user's home directory. - uid: 1024 + uid: user.uid shell: /bin/bash - name : set sudoers right lineinfile: - dest: '/etc/sudoers.d/{{username}}' + dest: '/etc/sudoers.d/{{user.name}}' regexp: '{{ item.regexp }}' line: '{{ item.line }}' state: 'present' @@ -34,8 +34,8 @@ mode: '0440' validate: 'visudo -cf "%s"' with_items: - - regexp: '^%{{username}}\s' - line: '%{{username}} ALL = (ALL) NOPASSWD:ALL' + - regexp: '^%{{user.name}}\s' + line: '%{{user.name}} ALL = (ALL) NOPASSWD:ALL' - name: Ensure /etc/sudoers includes /etc/sudoers.d @@ -48,13 +48,13 @@ - name: copy rsa key copy: - dest: /home/{{username}}/.ssh/ # required. Remote absolute path where the file should be copied to. If I(src) is a directory, this must be a directory too. If I(dest) is a nonexistent path and if either I(dest) ends with "/" or I(src) is a directory, I(dest) is created. If I(src) and I(dest) are files, the parent directory of I(dest) isn't created: the task fails if it doesn't already exist. + dest: /home/{{user.name}}/.ssh/ # required. Remote absolute path where the file should be copied to. If I(src) is a directory, this must be a directory too. If I(dest) is a nonexistent path and if either I(dest) ends with "/" or I(src) is a directory, I(dest) is created. If I(src) and I(dest) are files, the parent directory of I(dest) isn't created: the task fails if it doesn't already exist. src: "{{item}}" # not required. Local path to a file to copy to the remote server; can be absolute or relative. If path is a directory, it is copied recursively. In this case, if path ends with "/", only inside contents of that directory are copied to destination. Otherwise, if it does not end with "/", the directory itself with all contents is copied. This behavior is similar to Rsync. force: yes # not required. the default is C(yes), which will replace the remote file when contents are different than the source. If C(no), the file will only be transferred if the destination does not exist. remote_src: no # not required. If C(no), it will search for I(src) at originating/master machine.,If C(yes) it will go to the remote/target machine for the I(src). Default is C(no).,Currently I(remote_src) does not support recursive copying.,I(remote_src) only works with C(mode=preserve) as of version 2.6. mode: "600" # not required. Mode the file or directory should be. For those used to I(/usr/bin/chmod) remember that modes are actually octal numbers. You must either add a leading zero so that Ansible's YAML parser knows it is an octal number (like C(0644) or C(01777)) or quote it (like C('644') or C('1777')) so Ansible receives a string and can do its own conversion from string into number. Giving Ansible a number without following one of these rules will end up with a decimal number which will have unexpected results. As of version 1.8, the mode may be specified as a symbolic mode (for example, C(u+rwx) or C(u=rw,g=r,o=r)). As of version 2.3, the mode may also be the special string C(preserve). C(preserve) means that the file will be given the same permissions as the source file. selevel: s0 # not required. Level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the C(range). C(_default) feature works as for I(seuser). - owner: "{{username}}" # not required. Name of the user that should own the file/directory, as would be fed to I(chown). + owner: "{{user.name}}" # not required. Name of the user that should own the file/directory, as would be fed to I(chown). with_items: - id_rsa - authorized_keys From 089a2a553bca644e3ff970098ea0a1e3e621e1a5 Mon Sep 17 00:00:00 2001 From: vincent Date: Sun, 14 Apr 2019 11:46:22 +0200 Subject: [PATCH 5/5] fix issue --- tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index 08d36a4..c250e32 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -19,7 +19,7 @@ system: no # not required. When creating an account C(state=present), setting this to C(yes) makes the user a system account. This setting cannot be changed on existing users. state: present # not required. choices: absent;present. Whether the account should exist or not, taking action if the state is different from what is stated. ssh_key_file: .ssh/id_rsa # not required. Optionally specify the SSH key filename. If this is a relative filename then it will be relative to the user's home directory. - uid: user.uid + uid: "{{ user.uid }}" shell: /bin/bash - name : set sudoers right