From 3b75cb9f7742beef8c0173ce7cc4b4c53f2588f0 Mon Sep 17 00:00:00 2001 From: Sergei Bobkov Date: Sun, 29 Dec 2024 20:09:05 +0300 Subject: [PATCH] Made inventories config and scripts --- ansible/{ => .conf}/.ansible.cfg | 2 +- ansible/.conf/.config_ssh | 4 + ansible/.conf/.gitconfig | 5 + .../.ansible/inventories/group_vars/all.yml | 7 ++ ansible/.secret/.ansible/inventories/hosts | 14 +++ .../vmware_vm_inventory.sh | 3 + .../vmware_vm_inventory.yml | 98 +++++++++++++++++++ ansible/.secret/.ansible/vars_creds.yml | 12 +++ ansible/inventories/README.md | 13 --- ansible/inventories/group_vars/all.yml | 6 -- ansible/inventories/hosts | 17 ---- ansible/inventories/vmware_vm_inventory.yml | 45 --------- ansible/playbooks/os-ipxe-vmware-deploy.yml | 2 +- ansible/playbooks/os-linux-apt-update.yml | 2 +- ansible/playbooks/os-ping-test.yml | 2 +- ansible/playbooks/vmware_tmp/vm_get_info.yml | 2 +- .../playbooks/vmware_tmp/vm_guest_info.yml | 2 +- 17 files changed, 149 insertions(+), 87 deletions(-) rename ansible/{ => .conf}/.ansible.cfg (99%) create mode 100644 ansible/.conf/.config_ssh create mode 100644 ansible/.conf/.gitconfig create mode 100644 ansible/.secret/.ansible/inventories/group_vars/all.yml create mode 100644 ansible/.secret/.ansible/inventories/hosts create mode 100755 ansible/.secret/.ansible/inventories/vmware_vm_inventory/vmware_vm_inventory.sh create mode 100644 ansible/.secret/.ansible/inventories/vmware_vm_inventory/vmware_vm_inventory.yml create mode 100644 ansible/.secret/.ansible/vars_creds.yml delete mode 100644 ansible/inventories/README.md delete mode 100644 ansible/inventories/group_vars/all.yml delete mode 100644 ansible/inventories/hosts delete mode 100644 ansible/inventories/vmware_vm_inventory.yml diff --git a/ansible/.ansible.cfg b/ansible/.conf/.ansible.cfg similarity index 99% rename from ansible/.ansible.cfg rename to ansible/.conf/.ansible.cfg index 01a2c3b..dcf2bf9 100644 --- a/ansible/.ansible.cfg +++ b/ansible/.conf/.ansible.cfg @@ -12,7 +12,7 @@ # some basic default values... -inventory = $HOME/ansible/hosts +inventory = $HOME/.secret/.ansible/inventories remote_tmp = $HOME/.ansible/tmp forks = 15 sudo_user = root diff --git a/ansible/.conf/.config_ssh b/ansible/.conf/.config_ssh new file mode 100644 index 0000000..d17f1e4 --- /dev/null +++ b/ansible/.conf/.config_ssh @@ -0,0 +1,4 @@ +Host git.hostname.com + User git + IdentityFile ~/.ssh/id_rsa_git + ProxyCommand nc -X connect -x proxy.xxxxxxx.loc:3128 %h %p diff --git a/ansible/.conf/.gitconfig b/ansible/.conf/.gitconfig new file mode 100644 index 0000000..6c80bb7 --- /dev/null +++ b/ansible/.conf/.gitconfig @@ -0,0 +1,5 @@ +[user] + name = Name SureName + email = xxxxxxx@git.xxxxxx.ru +#[core] +# autocrlf = input diff --git a/ansible/.secret/.ansible/inventories/group_vars/all.yml b/ansible/.secret/.ansible/inventories/group_vars/all.yml new file mode 100644 index 0000000..928e4aa --- /dev/null +++ b/ansible/.secret/.ansible/inventories/group_vars/all.yml @@ -0,0 +1,7 @@ +--- +## Ansible params +ansible_port: '22' +ansible_ssh_user: 'root' +#ansible_ssh_password: 'XXXXXXXXX' +ansible_ssh_private_key_file: '~/.ssh/id_rsa_XXXXXXX' +ansible_python_interpreter: '/usr/bin/python3' diff --git a/ansible/.secret/.ansible/inventories/hosts b/ansible/.secret/.ansible/inventories/hosts new file mode 100644 index 0000000..ad3bc64 --- /dev/null +++ b/ansible/.secret/.ansible/inventories/hosts @@ -0,0 +1,14 @@ +[test] + +z3.lab.loc ansible_host=10.8.11.13 ansible_ssh_port=22 ansible_python_interpreter="/usr/bin/python3" + +[all_linux] +ovpnsrv01-infr-dmz.lab.loc ansible_host=10.1.1.11 ansible_ssh_port=22 ansible_python_interpreter="/usr/bin/python3" +ovpnsrv09-infr-dmz.lab.loc ansible_host=10.1.1.19 ansible_ssh_port=22 ansible_python_interpreter="/usr/bin/python3" +websrv99-it-dmz.lab.loc ansible_host=10.1.2.99 ansible_ssh_port=22 ansible_python_interpreter="/usr/bin/python3" +svcsrv01-it-dmz.lab.loc ansible_host=10.1.254.254 ansible_ssh_port=22 ansible_python_interpreter="/usr/bin/python3" +fakednssrv01-infr.lab.loc ansible_host=10.1.101.101 ansible_ssh_port=22 ansible_python_interpreter="/usr/bin/python3" +#autotoolsrv01-it.lab.loc ansible_host=10.1.222.11 ansible_ssh_port=22 ansible_python_interpreter="/usr/bin/python3" +lin-reposrv01-it.lab.loc ansible_host=10.1.254.51 ansible_ssh_port=22 ansible_python_interpreter="/usr/bin/python3" +rslogsrv01-it.lab.loc ansible_host=10.1.254.2 ansible_ssh_port=22 ansible_python_interpreter="/usr/bin/python3" +svcsrv01-it.lab.loc ansible_host=10.1.254.254 ansible_ssh_port=22 ansible_python_interpreter="/usr/bin/python3" diff --git a/ansible/.secret/.ansible/inventories/vmware_vm_inventory/vmware_vm_inventory.sh b/ansible/.secret/.ansible/inventories/vmware_vm_inventory/vmware_vm_inventory.sh new file mode 100755 index 0000000..ffe26e8 --- /dev/null +++ b/ansible/.secret/.ansible/inventories/vmware_vm_inventory/vmware_vm_inventory.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +ansible-inventory -i ~/.secret/.ansible/inventories/vmware_vm_inventory/vmware_vm_inventory.yml --list -y --output ~/.secret/.ansible/inventories/hosts.yml diff --git a/ansible/.secret/.ansible/inventories/vmware_vm_inventory/vmware_vm_inventory.yml b/ansible/.secret/.ansible/inventories/vmware_vm_inventory/vmware_vm_inventory.yml new file mode 100644 index 0000000..dfa0744 --- /dev/null +++ b/ansible/.secret/.ansible/inventories/vmware_vm_inventory/vmware_vm_inventory.yml @@ -0,0 +1,98 @@ +--- +# +# For use: +# ansible-inventory -i ~/.secret/.ansible/inventories/vmware_vm_inventory/vmware_vm_inventory.yml --list -y --output ~/.secret/.ansible/inventories/hosts_.yml +# cat zzz.yml | grep -i "guestid" | sed 's/^ config.guestId: //' | sed 's/$.*//' | sort | uniq +# +plugin: community.vmware.vmware_vm_inventory +strict: true +hostname: "vcsrv01.XXXXXXX.XXX" +username: "ansb-autotools-it@vsphere.local" +password: "XXXXXXXXXXXXXXXX" +validate_certs: false +with_tags: true +with_folders: true +with_nested_properties: true + +resources: + - datacenter: + - 'DC01' + resources: + - compute_resource: + - Cluster01 +# - folder: +# - VLAN-0222 + + +hostnames: + - config.name + +properties: + - 'name' + - 'config.name' + - 'guest.guestFamily' + - 'guest.guestFullName' +# - 'config' +# - 'guest' + - 'guest.ipAddress' + - 'config.guestId' + - 'summary.runtime.powerState' + - 'config.template' + +## - availableField +## - configIssue +## - configStatus +## - customValue +## - datastore +## - effectiveRole +## - guestHeartbeatStatus +## - layout +## - layoutEx +## - parent +## - name +## - network +## - overallStatus +## - parentVApp +## - permission +## - recentTask +## - resourcePool +## - rootSnapshot +## - snapshot +## - triggeredAlarmState +## - value +## - capability +## - config +## - guest +## - runtime +## - storage +## - summary + +filters: +- config.template == false +- summary.runtime.powerState == 'poweredOn' +- '"vCLS" not in config.name' +- '"vcsrv01.lab.loc" not in config.name' + +#"'Nas01' in config.datastoreUrl[0].name" +# or guest.ipAddress is match('192.169.*')) +#- config.guestId == 'debian12_64Guest' + +compose: + ansible_host: 'guest.ipAddress' +# composed_var: 'config.name' +# ansible_user: "'root'" +# ansible_connection: "'ssh'" +# ansible_ssh_private_key_file: "'~/.ssh/id_rsa_XXXXXX'" +# ansible_ssh_port: "'22'" +# ansible_python_interpreter: "'/usr/bin/python3'" + +groups: + VMs: true + +keyed_groups: + - key: config.guestId + separator: '' + - key: guest.guestFullName + separator: '' + - key: guest.guestFamily + separator: '' diff --git a/ansible/.secret/.ansible/vars_creds.yml b/ansible/.secret/.ansible/vars_creds.yml new file mode 100644 index 0000000..babd916 --- /dev/null +++ b/ansible/.secret/.ansible/vars_creds.yml @@ -0,0 +1,12 @@ +--- +vcenter_hostname: "vcs8srv01.lab.loc" +vcenter_username: "administrator@vsphere.local" +vcenter_password: "XXXXXXXXX" +vcenter_validate_certs: false +vcenter_datacenter: "DC01" + +ansible_user: "root" +#ansible_password: "XXXXXXX" +ansible_ssh_private_key_file: '~/.ssh/id_rsa_XXXXXXX' +ansible_ssh_port: 22 +ansible_python_interpreter: "/usr/bin/python3" diff --git a/ansible/inventories/README.md b/ansible/inventories/README.md deleted file mode 100644 index 91d1b37..0000000 --- a/ansible/inventories/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Inventory gets from VMVare vSphere -Add it to you Ansible config file ( /root/.ansible.cfg ):
- -`[inventory]`
-`enable_plugins = host_list, script, auto, yaml, ini, toml, community.vmware.vmware_vm_inventory`
-
-
-For use:
- -`ansible-inventory -i /root/ansible/inventories/vmware_vm_inventory.yml --list -y --output zzz.yml`
-`cat zzz.yml | grep -i "guestid" | sed 's/^ config.guestId: //' | sed 's/$.*//' | sort | uniq`
-
-
diff --git a/ansible/inventories/group_vars/all.yml b/ansible/inventories/group_vars/all.yml deleted file mode 100644 index 5cdcade..0000000 --- a/ansible/inventories/group_vars/all.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -## Ansible params -#ansible_port: '22' -#ansible_ssh_user: 'root' -#ansible_ssh_password: 'XXXXXXXXX' -#ansible_ssh_private_key_file: '~/.ssh/XXXXX.id_rsa' diff --git a/ansible/inventories/hosts b/ansible/inventories/hosts deleted file mode 100644 index 811d137..0000000 --- a/ansible/inventories/hosts +++ /dev/null @@ -1,17 +0,0 @@ - -dc01-ipxesrv01-it-infr.lab.loc ansible_host=10.8.221.2 - -z-debian-packer-vm ansible_host=10.8.221.115 -z-ubuntu-packer-vm ansible_host=10.8.221.118 - -aaa ansible_host=10.8.221.200 - - -## Do not edit and delete it ## -## It need for packer templetes ## -packer-templ-debian-11-x64 -packer-templ-debian-12-x64 -packer-templ-ubuntu-24-04-x64 -## Do not edit and delete it ## -## It need for packer templetes ## - diff --git a/ansible/inventories/vmware_vm_inventory.yml b/ansible/inventories/vmware_vm_inventory.yml deleted file mode 100644 index 5050815..0000000 --- a/ansible/inventories/vmware_vm_inventory.yml +++ /dev/null @@ -1,45 +0,0 @@ ---- -# -# For use: -# ansible-inventory -i ~/ansible/inventories/vmware_vm_inventory.yml --list -y --output zzz.yml -# cat zzz.yml | grep -i "guestid" | sed 's/^ config.guestId: //' | sed 's/$.*//' | sort | uniq -# -plugin: community.vmware.vmware_vm_inventory -strict: true -hostname: "vcs8srv01.lab.loc" -username: "administrator@vsphere.local" -password: "XXXXXXXXX" -validate_certs: false -with_tags: false -with_folders: true - -#resources: -# - datacenter: -# - 'DC01' -# resources: -# - compute_resource: -# - Cluster01 -# - folder: -# - VLAN-0222 - -hostnames: - - config.name -properties: - - name - - config.name - - guest -# - config.guestId - - summary.runtime.powerState -# - config.datastoreUrl - - config.template - -filters: -- config.template == false -- summary.runtime.powerState == 'poweredOn' - -keyed_groups: - - key: summary.runtime.powerState - separator: '' - -# - key: ipConfig.network -# separator: '' diff --git a/ansible/playbooks/os-ipxe-vmware-deploy.yml b/ansible/playbooks/os-ipxe-vmware-deploy.yml index 8c55d59..ddd124c 100644 --- a/ansible/playbooks/os-ipxe-vmware-deploy.yml +++ b/ansible/playbooks/os-ipxe-vmware-deploy.yml @@ -4,6 +4,6 @@ become: false gather_facts: false vars_files: - - /root/.secret/.ansible/vars_creds.yml + - ~/.secret/.ansible/vars_creds.yml roles: - os-ipxe-vmware-deploy diff --git a/ansible/playbooks/os-linux-apt-update.yml b/ansible/playbooks/os-linux-apt-update.yml index 62d7f22..9471633 100644 --- a/ansible/playbooks/os-linux-apt-update.yml +++ b/ansible/playbooks/os-linux-apt-update.yml @@ -4,7 +4,7 @@ become: false gather_facts: true vars_files: - - /root/.secret/.ansible/vars_creds.yml + - ~/.secret/.ansible/vars_creds.yml tasks: - name: Upgrage system type of Debian using apt block: diff --git a/ansible/playbooks/os-ping-test.yml b/ansible/playbooks/os-ping-test.yml index cc3a01c..e2e5fab 100644 --- a/ansible/playbooks/os-ping-test.yml +++ b/ansible/playbooks/os-ping-test.yml @@ -4,7 +4,7 @@ become: false gather_facts: true vars_files: - - /root/.secret/.ansible/vars_creds.yml + - ~/.secret/.ansible/vars_creds.yml tasks: - name: Debug diff --git a/ansible/playbooks/vmware_tmp/vm_get_info.yml b/ansible/playbooks/vmware_tmp/vm_get_info.yml index 5c4a012..44f12f3 100644 --- a/ansible/playbooks/vmware_tmp/vm_get_info.yml +++ b/ansible/playbooks/vmware_tmp/vm_get_info.yml @@ -7,7 +7,7 @@ vars_name: "dc01-ftpsrv01-it-infr.lab.loc" # vars_name: "debian12-common-templ" vars_files: - - /root/.secret/.ansible/vars_creds.yml + - ~/.secret/.ansible/vars_creds.yml tasks: - name: Get info VM diff --git a/ansible/playbooks/vmware_tmp/vm_guest_info.yml b/ansible/playbooks/vmware_tmp/vm_guest_info.yml index dfb27ad..9a4b68e 100644 --- a/ansible/playbooks/vmware_tmp/vm_guest_info.yml +++ b/ansible/playbooks/vmware_tmp/vm_guest_info.yml @@ -7,7 +7,7 @@ vars_name: "dc01-ftpsrv01-it-infr.lab.loc" # vars_name: "debian12-common-templ" vars_files: - - /root/.secret/.ansible/vars_creds.yml + - ~/.secret/.ansible/vars_creds.yml tasks: - name: Get info VM