diff --git a/ce-dev/ansible/vars/_common/user_deploy.yml b/ce-dev/ansible/vars/_common/user_deploy.yml index 0130b82cb..41ac2bc34 100644 --- a/ce-dev/ansible/vars/_common/user_deploy.yml +++ b/ce-dev/ansible/vars/_common/user_deploy.yml @@ -1,8 +1,6 @@ _user_deploy_username: ce-dev user_deploy: username: "{{ _user_deploy_username }}" - utility_host: "localhost" - utility_username: "{{ _user_deploy_username }}" sudo_config: entity_name: "{{ _user_deploy_username }}" hosts: "ALL" diff --git a/ce-dev/ansible/vars/_common/user_provision.yml b/ce-dev/ansible/vars/_common/user_provision.yml index 3fdc118c4..984f8a103 100644 --- a/ce-dev/ansible/vars/_common/user_provision.yml +++ b/ce-dev/ansible/vars/_common/user_provision.yml @@ -1,8 +1,6 @@ _user_provision_username: ce-dev user_provision: username: "{{ _user_provision_username }}" - utility_host: "localhost" - utility_username: "{{ _user_provision_username }}" sudo_config: entity_name: "{{ _user_provision_username }}" hosts: "ALL" diff --git a/ce-dev/ansible/vars/gitlab/ce_deploy.yml b/ce-dev/ansible/vars/gitlab/ce_deploy.yml index 5c5ae4499..3e30b2306 100644 --- a/ce-dev/ansible/vars/gitlab/ce_deploy.yml +++ b/ce-dev/ansible/vars/gitlab/ce_deploy.yml @@ -2,6 +2,5 @@ ce_deploy: own_repository: https://github.com/codeenigma/ce-deploy.git own_repository_branch: 1.x username: deploy - utility_username: deploy local_dir: /home/deploy/ce-deploy - ce_provision_dir: /home/ce-dev/ce-provision \ No newline at end of file + ce_provision_dir: /home/ce-dev/ce-provision diff --git a/install.sh b/install.sh index eddc31133..f8b7202ca 100755 --- a/install.sh +++ b/install.sh @@ -147,7 +147,6 @@ fi /usr/bin/su - "$CONTROLLER_USER" -c "/usr/bin/python3 -m venv /home/$CONTROLLER_USER/ce-python" /usr/bin/su - "$CONTROLLER_USER" -c "/home/$CONTROLLER_USER/ce-python/bin/python3 -m pip install --upgrade pip" /usr/bin/su - "$CONTROLLER_USER" -c "/home/$CONTROLLER_USER/ce-python/bin/pip install ansible netaddr python-debian" -/usr/bin/su - "$CONTROLLER_USER" -c "/home/$CONTROLLER_USER/ce-python/bin/ansible-galaxy collection install ansible.posix -p /home/$CONTROLLER_USER/.ansible/collections/ansible_collections --force" if [ "$AWS_SUPPORT" = "true" ]; then /usr/bin/su - "$CONTROLLER_USER" -c "/home/$CONTROLLER_USER/ce-python/bin/pip install boto3" fi @@ -167,6 +166,8 @@ else /usr/bin/echo "-------------------------------------------------" fi /usr/bin/mkdir -p "/home/$CONTROLLER_USER/ce-provision/galaxy/roles" +/usr/bin/su - "$CONTROLLER_USER" -c "cd /home/$CONTROLLER_USER/ce-provision && /home/$CONTROLLER_USER/ce-python/bin/ansible-galaxy collection install ansible.posix -p /home/$CONTROLLER_USER/ce-provision/galaxy/ansible_collections --force" + # Create playbook for ce-provision. /bin/cat >"/home/$CONTROLLER_USER/ce-provision/provision.yml" << EOL --- @@ -233,8 +234,6 @@ user_provision: create: false create_home: false update_password: always - utility_username: "${CONTROLLER_USER}" - utility_host: localhost sudo_config: entity_name: "${CONTROLLER_USER}" hosts: "ALL" diff --git a/plays/launcher/configure.yml b/plays/launcher/configure.yml new file mode 100644 index 000000000..4c802bb72 --- /dev/null +++ b/plays/launcher/configure.yml @@ -0,0 +1,57 @@ +--- +# Bare provisioning of a new server. +# Use this command to execute: +# +# cd /home/controller/ce-provision && \ +# ./scripts/provision.sh --workspace /home/controller/ce-provision \ +# --repo none --branch none \ +# --playbook /home/controller/ce-provision/plays/launcher/configure.yml \ +# --ansible-extra-vars "_provision_host=X.X.X.X" +# +# Replace X.X.X.X with your hostname or IP address. +- hosts: localhost + vars: + _ce_provision_username: controller + _add_host: true # set to false if you do not want to add the new server to hosts.yml + _ce_provision_config_branch: 2.x # change this if you didn't use our example config and have a different main branch name + tasks: + - name: Add the server to Ansible hosts in memory. + ansible.builtin.add_host: + hostname: "{{ _provision_host }}" + + - name: Add the server to hosts.yml. + when: _add_host + block: + - name: Edit hosts.yml file. + ansible.builtin.lineinfile: + path: "/home/{{ _ce_provision_username }}/ce-provision/config/hosts/hosts.yml" + line: "{{ _provision_host }}:" + create: true + + - name: Add hosts.yml changes. + ansible.builtin.command: git add . + args: + chdir: "/home/{{ _ce_provision_username }}/ce-provision/config" + + - name: Commit hosts.yml changes. + ansible.builtin.shell: "git diff --staged --quiet || git commit -m 'Ansible autogenerated - host {{ _provision_host }} added.'" + args: + chdir: "/home/{{ _ce_provision_username }}/ce-provision/config" + + - name: Push the hosts file change to the config repository. + ansible.builtin.command: "git push origin {{ _ce_provision_config_branch | default('main') }}" + args: + chdir: "/home/{{ _ce_provision_username }}/ce-provision/config" + +- hosts: "{{ _provision_host }}" + vars: + ansible_user: admin + _ce_provision_build_id: 0 + become: true + tasks: + - ansible.builtin.import_role: + name: _init + - ansible.builtin.import_role: + name: debian/user_provision + - ansible.builtin.import_role: + name: _exit diff --git a/roles/_init/defaults/main.yml b/roles/_init/defaults/main.yml index 017f953ff..d086d6a81 100644 --- a/roles/_init/defaults/main.yml +++ b/roles/_init/defaults/main.yml @@ -7,6 +7,7 @@ _venv_path: "/home/{{ _ce_provision_username }}/ce-python" _venv_command: /usr/bin/python3 -m venv _venv_install_username: "{{ _ce_provision_username }}" _ce_ansible_timer_name: upgrade_ansible +_env_type: unspecified # AWS variables - if you are using an AWS account, you can preset certain variables # Generally it is recommended to place these in your ce-provision-config repository under hosts/group_vars/all diff --git a/roles/debian/ce_deploy/tasks/main.yml b/roles/debian/ce_deploy/tasks/main.yml index 88e540b52..d67271386 100644 --- a/roles/debian/ce_deploy/tasks/main.yml +++ b/roles/debian/ce_deploy/tasks/main.yml @@ -47,7 +47,7 @@ ansible.builtin.git: repo: "{{ ce_deploy.own_repository | default('https://github.com/codeenigma/ce-deploy.git') }}" dest: "{{ ce_deploy.local_dir }}" - version: "{{ ce_deploy.own_repository_branch | default('master') }}" + version: "{{ ce_deploy.own_repository_branch | default('main') }}" update: true accept_hostkey: true become: true @@ -58,7 +58,7 @@ repo: "{{ ce_deploy.config_repository }}" accept_hostkey: true dest: "{{ _ce_provision_build_tmp_dir }}/config" - version: "{{ ce_deploy.config_repository_branch | default('master') }}" + version: "{{ ce_deploy.config_repository_branch | default('main') }}" become: false delegate_to: localhost when: ce_deploy.config_repository is defined and ce_deploy.config_repository diff --git a/roles/debian/ce_provision/tasks/main.yml b/roles/debian/ce_provision/tasks/main.yml index 30c3aeec3..ff7481f73 100644 --- a/roles/debian/ce_provision/tasks/main.yml +++ b/roles/debian/ce_provision/tasks/main.yml @@ -85,7 +85,7 @@ ansible.builtin.git: repo: "{{ ce_provision.own_repository | default('https://github.com/codeenigma/ce-provision.git') }}" dest: "{{ ce_provision.local_dir }}" - version: "{{ ce_provision.own_repository_branch | default('master') }}" + version: "{{ ce_provision.own_repository_branch | default('main') }}" update: true accept_hostkey: true #@todo? become: true @@ -98,7 +98,7 @@ repo: "{{ ce_provision.config_repository }}" accept_hostkey: true dest: "{{ ce_provision.local_dir }}/config" - version: "{{ ce_provision.config_repository_branch | default('master') }}" + version: "{{ ce_provision.config_repository_branch | default('main') }}" become: true become_user: "{{ ce_provision.username }}" when: diff --git a/roles/debian/user_ansible/defaults/main.yml b/roles/debian/user_ansible/defaults/main.yml index 7f42053a6..5bec6c2c8 100644 --- a/roles/debian/user_ansible/defaults/main.yml +++ b/roles/debian/user_ansible/defaults/main.yml @@ -11,9 +11,6 @@ user_ansible: # This is shown for documentation, you should do this in your config repo # uid: 999 # gid: 999 - # Local username of the deploy user. - utility_host: "localhost" - utility_username: "{{ _user_ansible_username }}" sudo_config: {} # an empty dictionary will skip creating a sudo config # Example sudo config allowing full sudo permissions - see the debian/sudo_config role for more details. # entity_name: "{{ _user_ansible_username }}" diff --git a/roles/debian/user_deploy/defaults/main.yml b/roles/debian/user_deploy/defaults/main.yml index 31934a720..718004a07 100644 --- a/roles/debian/user_deploy/defaults/main.yml +++ b/roles/debian/user_deploy/defaults/main.yml @@ -12,9 +12,6 @@ user_deploy: # This is shown for documentation, you should do this in your config repo # uid: 989 # gid: 989 - # Local username of the deploy user. - utility_host: "localhost" - utility_username: "{{ _user_deploy_username }}" sudo_config: {} # Example config allowing for feature branching. Allows manipulation of NGINX vhosts and cron.d files. # Uncomment to use. diff --git a/roles/debian/user_provision/defaults/main.yml b/roles/debian/user_provision/defaults/main.yml index 3bd885e27..6039727a2 100644 --- a/roles/debian/user_provision/defaults/main.yml +++ b/roles/debian/user_provision/defaults/main.yml @@ -11,9 +11,6 @@ user_provision: # This is shown for documentation, you should do this in your config repo # uid: 988 # gid: 988 - # Local username of the system user. - utility_host: "localhost" - utility_username: "{{ _user_provision_username }}" # Sudo configuration for full passwordless admin privileges. sudo_config: entity_name: "{{ _user_provision_username }}"