Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builds on HCI inventory and adds ARC support as well #1735

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

p3ck
Copy link
Collaborator

@p3ck p3ck commented Oct 4, 2024

SUMMARY

Adds support for listing ARC machines in inventory.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

plugins/action/azure_rm_arcssh.py
plugins/doc_fragments/azure_rm.py
plugins/inventory/azure_rm.py
plugins/modules/azure_rm_arcssh.py
plugins/plugin_utils/connectivity_utils.py
plugins/plugin_utils/constants.py
plugins/plugin_utils/file_utils.py
plugins/plugin_utils/ssh_info.py
requirements.txt

ADDITIONAL INFORMATION

SSH proxy setup is done via an action plugin. This provides the most flexibility for the user to configure the hosts the way they need to. They can group hosts based on tags and have different ssh permissions or keys depending on the group.

@p3ck p3ck added inventory plugin/Inventory/azure_rm.py related issues new_feature New feature requirments work in In trying to solve, or in working with contributors labels Oct 4, 2024
@p3ck p3ck force-pushed the hci_vms_inventory branch 3 times, most recently from 4fb6293 to 39dc14a Compare October 8, 2024 17:31
plugins/inventory/azure_rm.py Outdated Show resolved Hide resolved
plugins/inventory/azure_rm.py Outdated Show resolved Hide resolved
plugins/inventory/azure_rm.py Outdated Show resolved Hide resolved
plugins/inventory/azure_rm.py Outdated Show resolved Hide resolved
plugins/inventory/azure_rm.py Outdated Show resolved Hide resolved
By default ARC hosts will not show up in inventory, but you can use the
following inventory config to get them.

plugin: azure.azcollection.azure_rm
include_arc_resource_groups: ['*']

Use hostvar_expressions to modify the default ansible ssh config

hostvar_expressions:
   ansible_host: "resource_group + '-' + name if 'Microsoft.HybridCompute/machines' == resource_type else (public_dns_hostnames + public_ipv4_address) | first"
   ansible_ssh_common_args: "'-F /tmp/' + resource_group + '-' + name + '/ssh_config' if 'Microsoft.HybridCompute/machines' == resource_type"

Use keyed_groups to organize them or tags

keyed_groups:
  - prefix: "type"
    key: resource_type
    trailing_separator: false

Use the azure_rm_arcssh action plugin to configure the dynamic inventory
hosts with ssh proxy settings:

- name: Configure ARC SSH Proxy
  hosts: localhost
  connection: local
  tasks:
    - name: Setup Proxy
      azure.azcollection.azure_rm_arcssh:
        inventory_hostname: "{{ item }}"
        ansible_host: "{{ hostvars[item].ansible_host }}"
        local_user: admin
        resource_group: "{{ hostvars[item].resource_group }}"
        resource_type: "{{ hostvars[item].resource_type }}"
        private_key_file: "~/.ssh/id_rsa"
        ssh_config_file: "/tmp/{{ hostvars[item].resource_group }}-{{ item }}/ssh_config"
        ssh_relay_file: "/tmp/{{ hostvars[item].resource_group }}-{{ item }}/relay_info"
        ssh_proxy_folder: "~/.clientsshproxy"
      loop: "{{ groups['type_Microsoft_HybridCompute_machines'] }}"

- name: Ping ARC Hosts
  hosts: type_Microsoft_HybridCompute_machines
  tasks:
    - name: Ping
      ansible.builtin.ping:
Copy link
Contributor

@TiTi TiTi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i did not test azure_rm_arcssh.py

for arc inventory, see my inline comments

plugins/inventory/azure_rm.py Outdated Show resolved Hide resolved
plugins/doc_fragments/azure_rm.py Show resolved Hide resolved
for ipaddr in nic.get('ipAddresses', []):
ipAddressVersion = ipaddr.get('ipAddressVersion')
if ipAddressVersion == 'IPv4':
new_hostvars['ansible_all_ipv4_addresses'].append(ipaddr.get('address'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also fill private_ipv4_addresses ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we assume all IPv4 addresses are private?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I included the netaddr package and use is_global() to determine

@TiTi
Copy link
Contributor

TiTi commented Oct 24, 2024

remark, if I do:

include_vm_resource_groups: []
include_hcivm_resource_groups: []
include_arc_resource_groups: ["*"]

I notice that it gives me the arc objects, but also the stack hci vms (because they are arc objects).

We currently have no way to only list arc objects which are non-stack hci vms.
(i thought of filtering by resource_type but nope because it will be Microsoft.HybridCompute/machines even if this is a stack hci vm)

I'm not saying this needs to be fixed, this is just a remark.
But that would be nice though.

@p3ck p3ck removed the work in In trying to solve, or in working with contributors label Oct 24, 2024
@p3ck
Copy link
Collaborator Author

p3ck commented Nov 22, 2024

@Fred-sun Can you review? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inventory plugin/Inventory/azure_rm.py related issues new_feature New feature requirments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants