ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
820 stars 1.5k forks source link

Cannot reach lxc AND vm via ansible_host composing #7816

Open Denyreal opened 9 months ago

Denyreal commented 9 months ago

Summary

Hi folks.

i got this problem.

When i try to run a playbook on vm using proxm inventory plugin the ansible_host compose can't reach vm AND lxc at the same time but only alternatively.

here is my command :

ansible-playbook -i plugins/inventory/server1.proxmox.yml playbooks/debug_proxmox_inventory.yml

all vault are correctly setup.

It's a problem with compose ansible_host option which cannot compose vm AND lxc .

I can reach lxc with this one :

  ansible_host: proxmox_ipconfig0.ip | default(proxmox_net0.ip) | ipaddr('address')

I can reach vm with this

  ansible_host : ansible_host: proxmox_agent_interfaces | selectattr('name', 'in', 'eth0,ens18') | map(attribute='ip-addresses') | flatten | first | ipaddr('address')

it's similar to this problem :

https://forum.ansible.com/t/proxmox-dynamic-inventory-pull-ip-address-for-vm-lxc/1857

If someone can give me a hint it would be great.

Thank you very much ;)

Issue Type

Bug Report

Component Name

proxmox

Ansible Version

$ ansible --version
2.16.2

Community.general Version

$ ansible-galaxy collection list community.general
# /home/spin0/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 8.2.0  

# /usr/lib/python3.12/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 8.1.0  

# /usr/share/ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 8.0.2 

Configuration

$ ansible-config dump --only-changed
ANSIBLE_NOCOLOR(/home/spin0/ansible/ansible.cfg) = False                                                                                                                                      
ANSIBLE_NOCOWS(/home/spin0/ansible/ansible.cfg) = True                                                                                                                                        
COLOR_CHANGED(/home/spin0/ansible/ansible.cfg) = yellow                                                                                                                                       
COLOR_DEBUG(/home/spin0/ansible/ansible.cfg) = dark gray                                                                                                                                      
COLOR_DEPRECATE(/home/spin0/ansible/ansible.cfg) = purple                                                                                                                                     
COLOR_DIFF_ADD(/home/spin0/ansible/ansible.cfg) = green                                                                                                                                       
COLOR_DIFF_LINES(/home/spin0/ansible/ansible.cfg) = cyan                                                                                                                                      
COLOR_DIFF_REMOVE(/home/spin0/ansible/ansible.cfg) = red                                                                                                                                      
COLOR_ERROR(/home/spin0/ansible/ansible.cfg) = red                                                                                                                                            
COLOR_HIGHLIGHT(/home/spin0/ansible/ansible.cfg) = white                                                                                                                                      
COLOR_OK(/home/spin0/ansible/ansible.cfg) = green                                                                                                                                             
COLOR_SKIP(/home/spin0/ansible/ansible.cfg) = cyan                                                                                                                                            
COLOR_UNREACHABLE(/home/spin0/ansible/ansible.cfg) = red
COLOR_VERBOSE(/home/spin0/ansible/ansible.cfg) = blue
COLOR_WARN(/home/spin0/ansible/ansible.cfg) = bright purple
CONFIG_FILE() = /home/spin0/ansible/ansible.cfg 
DEFAULT_HOST_LIST(/home/spin0/ansible/ansible.cfg) = ['/home/spin0/ansible/hosts']
DEFAULT_INVENTORY_PLUGIN_PATH(/home/spin0/ansible/ansible.cfg) = ['/home/spin0/ansible/plugins/inventory']
DEFAULT_LOCAL_TMP(/home/spin0/ansible/ansible.cfg) = /home/spin0/.ansible/tmp/ansible-local-222066zvng_ag
DEFAULT_LOG_PATH(/home/spin0/ansible/ansible.cfg) = /tmp/ansible.log
DEFAULT_MODULE_PATH(/home/spin0/ansible/ansible.cfg) = ['/home/spin0/ansible/collections']
DEFAULT_NO_TARGET_SYSLOG(/home/spin0/ansible/ansible.cfg) = True
DEFAULT_ROLES_PATH(/home/spin0/ansible/ansible.cfg) = ['/home/spin0/ansible/roles']
DEFAULT_TIMEOUT(/home/spin0/ansible/ansible.cfg) = 60
DEFAULT_VAULT_PASSWORD_FILE(/home/spin0/ansible/ansible.cfg) = /home/spin0/ansible/vault_password
EDITOR(env: EDITOR) = /usr/bin/nano
HOST_KEY_CHECKING(/home/spin0/ansible/ansible.cfg) = False
INTERPRETER_PYTHON(/home/spin0/ansible/ansible.cfg) = python3.11
INVENTORY_ENABLED(/home/spin0/ansible/ansible.cfg) = ['yaml', 'constructed', 'ini', 'community.general.proxmox']

OS / Environment

ansible controller fedora 39 targeted host : proxmox 8.1.3

Steps to Reproduce

# More complete example demonstrating the use of 'want_facts' and the constructed options
# Note that using facts returned by 'want_facts' in constructed options requires 'want_facts=true'
# my.proxmox.yml
plugin: community.general.proxmox
url: https://192.168.10.30:8006
user: 6admin@pve
token_id: Administrator
# generated via echo -n 'YOURSUPERTOKEN' | ansible-vault encrypt_string
# the password has to be the same as your vault for more convenience
token_secret: !vault |
          $ANSIBLE_VAULT;1.1;AES256
          BLABLA

validate_certs: false
want_facts: true
exclude_nodes: true
groups:
  preprod_vm: "'preprod' in (proxmox_tags_parsed|list) and hostvars[inventory_hostname].proxmox_type|default('') == 'qemu'"
  preprod_ct: "'preprod' in (proxmox_tags_parsed|list) and hostvars[inventory_hostname].proxmox_type|default('') == 'lxc'"
  prod_vm: "'prod' in (proxmox_tags_parsed|list) and hostvars[inventory_hostname].proxmox_type|default('') == 'qemu'"
  prod_ct: " prod' in (proxmox_tags_parsed|list) and hostvars[inventory_hostname].proxmox_type|default('') == 'lxc'"
  lab_vm: "'lab' in (proxmox_tags_parsed|list) and hostvars[inventory_hostname].proxmox_type|default('') == 'qemu'"
  lab_ct: "'lab' in (proxmox_tags_parsed|list) and hostvars[inventory_hostname].proxmox_type|default('') == 'lxc'"
  # Repeat similar lines for other groups

want_proxmox_nodes_ansible_host: true
# Create hostvars
compose:
  ansible_port: 22
  ansible_user: "'ansible'"
  ansible_ssh_private_key_file: "'~/.ssh/mars.lab'"
  ansible_become_method: "'sudo'"
  ansible_become_password: !vault |
    $ANSIBLE_VAULT;1.1;AES256
    BLABLA

  ansible_host: proxmox_ipconfig0.ip | default(proxmox_net0.ip) | ipaddr('address')
...

Expected Results

i expected plugin to access all lxc and vm . i can access lxc (pgsql) but not vm (medialife)

Actual Results

ok: [pgsql]
fatal: [medialife]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname medialife: Name or service not known", "unreachable": true}

Code of Conduct

ansibullbot commented 9 months ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 9 months ago

cc @Ajpantuso @Thulium-Drake @UnderGreen @joshainglis @karmab click here for bot help

Denyreal commented 9 months ago

it solves the issue :

https://github.com/ansible-collections/community.general/issues/4854

felixfontein commented 9 months ago

!component =plugins/inventory/proxmox.py

ansibullbot commented 9 months ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 9 months ago

cc @ilijamt click here for bot help

TrendMend commented 8 months ago

it solves the issue :

4854

Could you follow up on what you mean? which comment resolved the issue?

ansibullbot commented 7 months ago

cc @krauthosting click here for bot help