From be6f184b818b91859ed0a40ebf1cc028507ba670 Mon Sep 17 00:00:00 2001 From: richard Date: Sat, 20 Aug 2022 13:34:56 -0400 Subject: [PATCH] update bootstrap.yaml to work with user supplied from cli --- ansible-5/inventory.ini | 2 ++ ansible-5/playbooks/bootstrap.yaml | 27 +++++++++++++-------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/ansible-5/inventory.ini b/ansible-5/inventory.ini index f0553c4..d348806 100644 --- a/ansible-5/inventory.ini +++ b/ansible-5/inventory.ini @@ -3,10 +3,12 @@ localhost ansible_connection=local [managed] home ansible_ssh_host=192.168.4.11 cubox-i ansible_ssh_host=192.168.4.12 +cubox-m ansible_ssh_host=192.168.4.15 [ns] home ansible_ssh_host=192.168.4.11 cubox-i ansible_ssh_host=192.168.4.12 +cubox-m ansible_ssh_host=192.168.4.15 [gfs] ;home ansible_ssh_host=192.168.4.11 diff --git a/ansible-5/playbooks/bootstrap.yaml b/ansible-5/playbooks/bootstrap.yaml index c505668..e31065d 100644 --- a/ansible-5/playbooks/bootstrap.yaml +++ b/ansible-5/playbooks/bootstrap.yaml @@ -1,7 +1,7 @@ --- - name: bootstrap hosts: cubox-m - remote_user: ansible +# remote_user: ansible gather_facts: false # become: true @@ -14,17 +14,6 @@ - name: Creates .ssh directory file: path=~/.ssh state=directory mode=700 - - name: remove debian user if it exists - command: userdel -rf debian - become: true - args: - removes: /home/debian/.bashrc - -# - name: remove ubuntu user if it exists -# command: userdel -rf ubuntu -# args: -# removes: /home/ubuntu/.bashrc - - debug: var=ansible_os_family run_once: true @@ -43,7 +32,7 @@ shell: /bin/bash create_home: yes password: "$6$7z7PfYwduXom0o73$DEiy3K15URNNjmKkOQIwx8/mFKArUNYkFn8D/4q6t/eP9hf1X9jnG4YuSjI7q1Dnp1HwukZUxZY7cF2JK5DO/." - uid: "1001" +# uid: "1001" groups: - sudo @@ -88,7 +77,7 @@ shell: /bin/bash create_home: yes password: "$6$yNKLUxX0$lxy/jaJI7cKCq5j.KondUalu9r96gUeRR//5qciZ/RX9z9PGSpbU9j7OsxaOzqV5uLeQ9ouIe8quo/2YqKE46/" - uid: "1000" +# uid: "1000" groups: - sudo @@ -102,3 +91,13 @@ with_file: - '/home/richard/.ssh/id_rsa.pub' + - name: remove {{item}} user if it exists + command: userdel -rf {{item}} + become: true + become_user: ansible + args: + removes: /home/{{item}}/.bashrc + loop: + - debian + - ubuntu +