--- # tasks file for ansible_bootstrap - name: detect debian raw: uname -a|grep debian||true register: debian - name: "install python and archlinux-keyring" raw: pacman -Sy python archlinux-keyring --noconfirm when: not debian.stdout - name: "install python for debian" raw: apt-get install python --assume-yes when: debian.stdout - name: upgrade system for arch pacman: state: latest # not required. choices: absent;latest;present. Desired state of the package. upgrade: true # not required. Whether or not to upgrade whole system. force: true # not required. When removing package - force remove package, without any checks. When update_cache - force redownload repo databases. update_cache: true become: yes register: upgrade when: not debian.stdout - name: upgrade system for debian apt: update_cache: yes # not required. Run the equivalent of C(apt-get update) before the operation. Can be run as part of the package installation or as a separate step. only_upgrade: yes # not required. Only upgrade a package if it is already installed. upgrade: full # not required. choices: dist;full;no;safe;yes. If yes or safe, performs an aptitude safe-upgrade.,If full, performs an aptitude full-upgrade.,If dist, performs an apt-get dist-upgrade.,Note: This does not upgrade a specific package, use state=latest for that.,Note: Since 2.4, apt-get is used as a fall-back if aptitude is not present. state: latest # not required. choices: absent;build-dep;latest;present. Indicates the desired package state. C(latest) ensures that the latest version is installed. C(build-dep) ensures the package build dependencies are installed. become: yes when: debian.stdout register: upgrade - debug: var: upgrade # not required. A variable name to debug. Mutually exclusive with the 'msg' option. - name: Reboot updates to apply reboot: reboot_timeout: 3600 when: upgrade.changed and "linux" in upgrade.packages and not debian.stdout become: yes - name: sudoers install package: state: present # not required. choices: absent;latest;present. Desired state of the package. name: sudo # not required. Name or list of names of the packages to install, upgrade, or remove. update_cache: true # not required. Whether or not to refresh the master package lists. This can be run as part of a package installation or as a separate step. - name: create profil user: 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: "{{ user.uid }}" shell: /bin/bash - name : set sudoers right lineinfile: dest: '/etc/sudoers.d/{{user.name}}' regexp: '{{ item.regexp }}' line: '{{ item.line }}' state: 'present' create: True owner: 'root' group: 'root' mode: '0440' validate: 'visudo -cf "%s"' with_items: - regexp: '^%{{user.name}}\s' line: '%{{user.name}} ALL = (ALL) NOPASSWD:ALL' - name: Ensure /etc/sudoers includes /etc/sudoers.d lineinfile: dest: '/etc/sudoers' regexp: '^#includedir\s+/etc/sudoers.d$' line: '#includedir /etc/sudoers.d' state: 'present' validate: 'visudo -cf "%s"' - name: copy rsa key for user copy: 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: "{{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 - id_gitea - config - name: copy rsa key for root copy: dest: /root/.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). with_items: - id_gitea - config - name: Remove root SSH access lineinfile: dest: /etc/ssh/sshd_config regexp: "^PermitRootLogin" line: "PermitRootLogin no" state: present notify: restart ssh