From 3d6c0f44d0bd0f87712e42ea9cfb8d14f522efbb Mon Sep 17 00:00:00 2001 From: Khue Doan Date: Wed, 3 Mar 2021 02:11:50 +0700 Subject: [PATCH] Use var for LXD password --- metal/Makefile | 8 +++-- metal/playbook.yml | 6 ++-- metal/roles/lxd/tasks/main.yml | 36 +++++++++---------- metal/roles/lxd/templates/leader.yaml.j2 | 2 +- metal/roles/lxd/templates/member.yaml.j2 | 2 +- .../templates/http/kickstart/centos8.ks.j2 | 2 +- 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/metal/Makefile b/metal/Makefile index 6eb471b1..7155a9cb 100644 --- a/metal/Makefile +++ b/metal/Makefile @@ -1,6 +1,6 @@ .POSIX: -default: init run +default: init provision init: python3 -m venv .venv \ @@ -8,6 +8,10 @@ init: && pip3 install --upgrade pip \ && pip3 install -r requirements.txt -run: +reset: . .venv/bin/activate \ && ansible-playbook --ask-become-pass --inventory hosts.ini playbook.yml + +provision: + . .venv/bin/activate \ + && ansible-playbook --inventory hosts.ini playbook.yml --tags provision diff --git a/metal/playbook.yml b/metal/playbook.yml index e929367b..2db30341 100644 --- a/metal/playbook.yml +++ b/metal/playbook.yml @@ -2,10 +2,10 @@ hosts: all gather_facts: no vars_prompt: - - name: username + - name: os_username prompt: Enter username for metal nodes private: no - - name: password + - name: os_password prompt: Enter password for metal nodes roles: - pxe-boot @@ -18,3 +18,5 @@ roles: - snap - lxd + tags: + - provision diff --git a/metal/roles/lxd/tasks/main.yml b/metal/roles/lxd/tasks/main.yml index 27889ec3..9346ed8f 100644 --- a/metal/roles/lxd/tasks/main.yml +++ b/metal/roles/lxd/tasks/main.yml @@ -27,22 +27,22 @@ creates: /var/snap/lxd/common/lxd/server.crt when: inventory_hostname != groups['metal'][0] -- name: Add remote - command: - argv: - - lxc - - remote - - add - - vagrant - - "{{ hostvars[groups['metal'][0]]['ansible_host'] }}" - - --accept-certificate - - --password - - 1 +# - name: Add remote +# command: +# argv: +# - lxc +# - remote +# - add +# - vagrant +# - "{{ hostvars[groups['metal'][0]]['ansible_host'] }}" +# - --accept-certificate +# - --password +# - 1 -- name: Change default remote - command: - argv: - - lxc - - remote - - switch - - vagrant +# - name: Change default remote +# command: +# argv: +# - lxc +# - remote +# - switch +# - vagrant diff --git a/metal/roles/lxd/templates/leader.yaml.j2 b/metal/roles/lxd/templates/leader.yaml.j2 index 0887b390..9cc6bf33 100644 --- a/metal/roles/lxd/templates/leader.yaml.j2 +++ b/metal/roles/lxd/templates/leader.yaml.j2 @@ -1,6 +1,6 @@ config: core.https_address: {{ hostvars[inventory_hostname]['ansible_host'] }}:8443 - core.trust_password: "1" + core.trust_password: {{ lxd_password }} networks: - config: bridge.mode: fan diff --git a/metal/roles/lxd/templates/member.yaml.j2 b/metal/roles/lxd/templates/member.yaml.j2 index fa7eaa88..d4d41775 100644 --- a/metal/roles/lxd/templates/member.yaml.j2 +++ b/metal/roles/lxd/templates/member.yaml.j2 @@ -5,4 +5,4 @@ cluster: cluster_certificate: | {{ hostvars[groups['metal'][0]]['server_cert']['content'] | b64decode | indent(width=4) }} server_address: {{ hostvars[inventory_hostname]['ansible_host'] }}:8443 - cluster_password: "1" + cluster_password: {{ lxd_password }} diff --git a/metal/roles/pxe-boot/templates/http/kickstart/centos8.ks.j2 b/metal/roles/pxe-boot/templates/http/kickstart/centos8.ks.j2 index b9806887..59fabbff 100644 --- a/metal/roles/pxe-boot/templates/http/kickstart/centos8.ks.j2 +++ b/metal/roles/pxe-boot/templates/http/kickstart/centos8.ks.j2 @@ -30,7 +30,7 @@ services --enabled="chronyd" timezone Asia/Ho_Chi_Minh --isUtc # Create user -user --groups=wheel --name={{ username }} --password={{ password }} +user --groups=wheel --name={{ os_username }} --password={{ os_password }} # Add SSH key sshkey --username=root "{{ ssh_public_key }}"