From ad8e3cc15559a934b2c6c96a7349df2db5d333e1 Mon Sep 17 00:00:00 2001 From: hybris Date: Tue, 22 Jan 2019 13:22:12 +0100 Subject: [PATCH] replace hard-coded usernames with remote_user variable --- 1-terraform.yml | 22 +++++++++++----------- roles/kubernetes/files/kubernetes.repo | 8 ++++++++ roles/kubernetes/tasks/main.yml | 5 ++++- roles/terraform/files/cloud-init.cfg.j2 | 10 +++++----- roles/terraform/tasks/main.yml | 16 ++++++++-------- 5 files changed, 36 insertions(+), 25 deletions(-) create mode 100644 roles/kubernetes/files/kubernetes.repo diff --git a/1-terraform.yml b/1-terraform.yml index 3f7be94..a5c5b4e 100644 --- a/1-terraform.yml +++ b/1-terraform.yml @@ -34,40 +34,40 @@ - name: create vm definitions template: src: "roles/terraform/files/cloud-init.tf.j2" - dest: "/home/hybris/terraform/{{ item.hostname }}.tf" - owner: hybris - group: hybris + dest: "/home/{{ remote_user }}/terraform/{{ item.hostname }}.tf" + owner: {{ remote_user }} + group: {{ remote_user }} with_items: "{{ kubernetes }}" - name: create cloud-init config template: src: "roles/terraform/files/cloud-init.cfg.j2" - dest: "/home/hybris/terraform/{{ item.hostname }}.cloud_init.cfg" - owner: hybris - group: hybris + dest: "/home/{{ remote_user }}/terraform/{{ item.hostname }}.cloud_init.cfg" + owner: {{ remote_user }} + group: {{ remote_user }} with_items: "{{ kubernetes }}" - name: create libvirt_provider config copy: src: roles/terraform/files/libvirt_provider.tf - dest: /home/hybris/terraform/libvirt_provider.tf + dest: /home/{{ remote_user }}/terraform/libvirt_provider.tf - name: delete statefile if it exists file: - path: /home/hybris/terraform/terraform.tfstate + path: /home/{{ remote_user }}/terraform/terraform.tfstate state: absent - name: initialize terraform shell: terraform init args: - chdir: /home/hybris/terraform + chdir: /home/{{ remote_user }}/terraform - name: plan terraform shell: terraform plan -out=cloud-init-plan args: - chdir: /home/hybris/terraform + chdir: /home/{{ remote_user }}/terraform - name: apply terraform shell: terraform apply "cloud-init-plan" args: - chdir: /home/hybris/terraform + chdir: /home/{{ remote_user }}/terraform diff --git a/roles/kubernetes/files/kubernetes.repo b/roles/kubernetes/files/kubernetes.repo new file mode 100644 index 0000000..81eefdf --- /dev/null +++ b/roles/kubernetes/files/kubernetes.repo @@ -0,0 +1,8 @@ +[kubernetes] +name=Kubernetes +baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 +enabled=1 +gpgcheck=1 +repo_gpgcheck=1 +gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg + https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg \ No newline at end of file diff --git a/roles/kubernetes/tasks/main.yml b/roles/kubernetes/tasks/main.yml index a604c7f..5546fee 100644 --- a/roles/kubernetes/tasks/main.yml +++ b/roles/kubernetes/tasks/main.yml @@ -47,6 +47,8 @@ #### KERNEL TASKS #### ###################### + +# TODO: get rid of inline http_proxy and fetch repo with the yum-repository ansible module - name: import elrepo gpg key shell: rpm -httpproxy http://[2001:470:6d:22c::1]:3128 --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org @@ -120,9 +122,10 @@ - name: add docker-ce yum repository shell: yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo + - name: copy kubernetes repo config copy: - src: /Users/hybris/dev/k8s-ansible/files/kubernetes.repo + src: ../files/kubernetes.repo dest: /etc/yum.repos.d/kubernetes.repo - name: install packages diff --git a/roles/terraform/files/cloud-init.cfg.j2 b/roles/terraform/files/cloud-init.cfg.j2 index db61c36..c93397b 100644 --- a/roles/terraform/files/cloud-init.cfg.j2 +++ b/roles/terraform/files/cloud-init.cfg.j2 @@ -1,6 +1,6 @@ #cloud-config users: - - name: hybris + - name: {{ remote_user }} lock-passwd: false passwd: $1$tG6Uv4$BPCIRF6RFuLrJ.lQO1GB8. sudo: ALL=(ALL) NOPASSWD:ALL @@ -12,9 +12,9 @@ write_files: # inet6_addr=$(ip a s | grep "inet6 2001:470:6d:22c:" | awk '{print substr($2,0)}') sudo hostnamectl set-hostname {{ item.hostname }} sudo ip -6 addr add {{ item.ipv6 }}/64 dev eth0 - sudo chown -R hybris:hybris /home/hybris - path: /home/hybris/cloud-init.sh - owner: hybris:hybris + sudo chown -R {{ remote_user }}:{{ remote_user }} /home/{{ remote_user }} + path: /home/{{ remote_user }}/cloud-init.sh + owner: {{ remote_user }}:{{ remote_user }} permissions: '0744' runcmd: - - [ '/home/hybris/cloud-init.sh' ] + - [ '/home/{{ remote_user }}/cloud-init.sh' ] diff --git a/roles/terraform/tasks/main.yml b/roles/terraform/tasks/main.yml index 6f57123..4979a0f 100644 --- a/roles/terraform/tasks/main.yml +++ b/roles/terraform/tasks/main.yml @@ -36,32 +36,32 @@ - name: go install terraform-provider-libvirt shell: /usr/local/go/bin/go install args: - chdir: /home/hybris/go/src/github.com/dmacvicar/terraform-provider-libvirt + chdir: /home/{{ remote_user }}/go/src/github.com/dmacvicar/terraform-provider-libvirt - name: create terraform config directory file: - path: /home/hybris/.terraform.d/ + path: /home/{{ remote_user }}/.terraform.d/ state: directory - name: create terraform plugin directory file: - path: /home/hybris/.terraform.d/plugins + path: /home/{{ remote_user }}/.terraform.d/plugins state: directory - name: install terraform-provider-libvirt copy: - src: /home/hybris/go/bin/terraform-provider-libvirt - dest: /home/hybris/.terraform.d/plugins/terraform-provider-libvirt + src: /home/{{ remote_user }}/go/bin/terraform-provider-libvirt + dest: /home/{{ remote_user }}/.terraform.d/plugins/terraform-provider-libvirt mode: 0777 - owner: hybris + owner: {{ remote_user }} remote_src: yes - name: delete terraform directory file: - path: /home/hybris/terraform + path: /home/{{ remote_user }}/terraform state: absent - name: create terraform directory file: - path: /home/hybris/terraform + path: /home/{{ remote_user }}/terraform state: directory