From ebae058a0b52016ab4ae54acdc41ab8e21b992aa Mon Sep 17 00:00:00 2001 From: richard Date: Wed, 22 Dec 2021 10:09:00 -0500 Subject: [PATCH] bootstrap and ping playbooks for new ansible --- ansible-5/ansible.cfg | 5 +++ ansible-5/cli/install-python | 2 +- ansible-5/cli/play/.help | 1 + ansible-5/cli/play/bootstrap | 3 ++ ansible-5/cli/play/bootstrap.help | 3 ++ ansible-5/cli/play/bootstrap.usage | 1 + ansible-5/inventory.ini | 17 ++++++++++ ansible-5/playbooks/bootstrap.yaml | 50 ++++++++++++++++++++++++++++++ ansible-5/playbooks/ping.yaml | 8 +++++ 9 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 ansible-5/ansible.cfg create mode 100644 ansible-5/cli/play/.help create mode 100755 ansible-5/cli/play/bootstrap create mode 100644 ansible-5/cli/play/bootstrap.help create mode 100644 ansible-5/cli/play/bootstrap.usage create mode 100644 ansible-5/inventory.ini create mode 100644 ansible-5/playbooks/bootstrap.yaml create mode 100644 ansible-5/playbooks/ping.yaml diff --git a/ansible-5/ansible.cfg b/ansible-5/ansible.cfg new file mode 100644 index 0000000..4d568a1 --- /dev/null +++ b/ansible-5/ansible.cfg @@ -0,0 +1,5 @@ +# local ansible config file +[defaults] +inventory = ./inventory.ini +remote_user = ansible +roles_path = ./roles diff --git a/ansible-5/cli/install-python b/ansible-5/cli/install-python index 651b997..ad27383 100755 --- a/ansible-5/cli/install-python +++ b/ansible-5/cli/install-python @@ -1,7 +1,7 @@ #!/usr/bin/env bash venvironment='venv' -sudo apt install -y python-is-python3 python3-pip python3-argcomplete +sudo apt install -y python-is-python3 python3-pip python3-argcomplete sshpass python -m pip install --user virtualenv python -m virtualenv ${venvironment} diff --git a/ansible-5/cli/play/.help b/ansible-5/cli/play/.help new file mode 100644 index 0000000..6d15d51 --- /dev/null +++ b/ansible-5/cli/play/.help @@ -0,0 +1 @@ +TODO: Add help for this directory diff --git a/ansible-5/cli/play/bootstrap b/ansible-5/cli/play/bootstrap new file mode 100755 index 0000000..9bcc7dc --- /dev/null +++ b/ansible-5/cli/play/bootstrap @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +ansible-playbook playbooks/bootstrap.yaml -i inventory.ini --ask-pass --ask-become-pass diff --git a/ansible-5/cli/play/bootstrap.help b/ansible-5/cli/play/bootstrap.help new file mode 100644 index 0000000..7aa5493 --- /dev/null +++ b/ansible-5/cli/play/bootstrap.help @@ -0,0 +1,3 @@ +ARGS - The arguments you wish to provide to this command + +TODO: Fill out the help information for this command. diff --git a/ansible-5/cli/play/bootstrap.usage b/ansible-5/cli/play/bootstrap.usage new file mode 100644 index 0000000..5226895 --- /dev/null +++ b/ansible-5/cli/play/bootstrap.usage @@ -0,0 +1 @@ +ARGS... diff --git a/ansible-5/inventory.ini b/ansible-5/inventory.ini new file mode 100644 index 0000000..1fcdb23 --- /dev/null +++ b/ansible-5/inventory.ini @@ -0,0 +1,17 @@ +localhost ansible_connection=local + +[managed] +home ansible_ssh_host=192.168.4.11 +cubox-i ansible_ssh_host=192.168.4.12 + +[ns] +home ansible_ssh_host=192.168.4.22 +cubox-i ansible_ssh_host=192.168.4.12 + +[gfs] +home ansible_ssh_host=192.168.4.11 +cubox-i ansible_ssh_host=192.168.4.12 + +;[desktop] +;richard-desktop ansible_connection=local + diff --git a/ansible-5/playbooks/bootstrap.yaml b/ansible-5/playbooks/bootstrap.yaml new file mode 100644 index 0000000..4ee3aaf --- /dev/null +++ b/ansible-5/playbooks/bootstrap.yaml @@ -0,0 +1,50 @@ +--- +- name: bootstrap + hosts: all + remote_user: richard + gather_facts: false +# become: true + + pre_tasks: +# - raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal) + - setup: # aka gather_facts + - name: Creates .ssh directory + file: path=~/.ssh state=directory mode=700 + +# - name: remove ubuntu user if it exists +# command: userdel -rf ubuntu +# args: +# removes: /home/ubuntu/.bashrc + + - debug: var=ansible_os_family + run_once: true + + - debug: var=ansible_architecture + run_once: true + + tasks: + - name: ping + ansible.builtin.ping: + + - name: Add the user 'ansible' + become: true + ansible.builtin.user: + name: ansible + state: present + shell: /bin/bash + create_home: yes + password: "$6$7z7PfYwduXom0o73$DEiy3K15URNNjmKkOQIwx8/mFKArUNYkFn8D/4q6t/eP9hf1X9jnG4YuSjI7q1Dnp1HwukZUxZY7cF2JK5DO/." + uid: "1001" + groups: + - sudo +# generate_ssh_key: yes +# ssh_keys: +# - "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAmJSdmj03d4fnZUuRByevPDNiReEk1fRL+7F9WPCo5zn+r5Oj84HXxd4P03DNXeGSBYmUAnsTqYEGdkjkpSrKfMm9bv8amL7hUC+Mzb+wOmXmyX1cw/SearYCBQRCz1s5p7I9+PO7XWaC0VJ99LUm1Bp4JM149U5X0Y3M2j2XV+0= RSA-1024" + + - name: Add the authorized key for 'ansible' + become: true + ansible.posix.authorized_key: + user: ansible + state: present + key: "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAmJSdmj03d4fnZUuRByevPDNiReEk1fRL+7F9WPCo5zn+r5Oj84HXxd4P03DNXeGSBYmUAnsTqYEGdkjkpSrKfMm9bv8amL7hUC+Mzb+wOmXmyX1cw/SearYCBQRCz1s5p7I9+PO7XWaC0VJ99LUm1Bp4JM149U5X0Y3M2j2XV+0= RSA-1024" +# key: "{{ lookup('file', '/home/charlie/.ssh/id_rsa.pub') }}" diff --git a/ansible-5/playbooks/ping.yaml b/ansible-5/playbooks/ping.yaml new file mode 100644 index 0000000..aeb5cc3 --- /dev/null +++ b/ansible-5/playbooks/ping.yaml @@ -0,0 +1,8 @@ +--- +- name: ping + hosts: all + gather_facts: false + + tasks: + - name: ping + ansible.builtin.ping: