[ansible-project] Re: trying to debug ansible and win_package

2024-01-12 Thread jbor...@gmail.com
The only time this error ever appears is if you have a timeout set on the 
task [1]. Check to ensure you don't have that config entry set 
'ansible-config dump --only-changed' or haven't set it on the task play.

[1] 
https://docs.ansible.com/ansible/latest/reference_appendices/config.html#task-timeout

On Saturday, January 13, 2024 at 2:43:41 AM UTC+10 Divan Santana wrote:

> Hi,
>
> I'm trying to debug a ansible windows issue, if someone with powershell
> knowledge could help me debug it, it would be great.
>
> I can successfully win_ping win_setup the windows 2019SE server, but not
> win_package install or install using chocolatey. No idea why.
>
> I have this piece of ansible code, to install a package via win_package.
>
> - name: Ensure 7-Zip is installed through win_package
> win_package:
> path: C:\temp\7z.exe
> state: present
>
> The above fails with:
>
> The win_package action failed to execute in the expected time frame (5) 
> and was terminated.
>
> I run my playbook with -v, I see this[1] in the output. I believe
> to debug this further I need to run the powershell script on the windows
> box directly. I'm not quite sure how to do that. What I've done is
> enable powershell script block logging, so that I can decode the
> EncodedCommand string (not sure how else to decode it?). Looking at the
> Event Viewer, I can see that the powershell script block is this[2].
>
> I'm rather clueless with powershell. I'm now stuck at, how can I
> execute this powershell script block[2] in the same manner as ansible is
> doing it, to see why it's failing to install? Currently I take the
> scriptblock[2] as is and paste it in powershell which simply returns
> nothing to the screen.
>
> Any help would be appreciated. Version details in [3].
>
>
> [1]:
> Using module file 
> /home/opc/.ansible/collections/ansible_collections/ansible/windows/plugins/modules/win_package.ps1
> Pipelining is enabled.
> <10.20.100.184> ESTABLISH WINRM CONNECTION FOR USER: opc on PORT 5986 TO 
> 10.20.100.184
> <10.20.100.184> WINRM CONNECT: transport=credssp endpoint=
> https://10.20.100.184:5986/wsman
> <10.20.100.184> WINRM OPEN SHELL: 37E74DAA-A27C-4642-89BB-CDDD11AF95DF
> EXEC (via pipeline wrapper)
> <10.20.100.184> WINRM EXEC 'PowerShell' ['-NoProfile', '-NonInteractive', 
> '-ExecutionPolicy', 'Unrestricted', '-EncodedCommand', 
> 

Re: [ansible-project] Trying to replace single quote with regex_replace

2024-01-12 Thread Vladimir Botka
> > On Jan 10, 2024, at 12:16 PM, Vladimir Botka  wrote:
> > FWIW, convert the string to a list
> >
> > s: "['/First Datacenter/vm/Prod-SRM']"
> > l: "{{ s|from_yaml }}"

On Fri, 12 Jan 2024 09:05:16 -0800 (PST)
Dimitri Yioulos  wrote:
> how is that actually written in the playbook?


For example,

shell> cat pb1.yml
- hosts: all
  vars:
s: "['/First Datacenter/vm/Prod-SRM']"
l: "{{ s|from_yaml }}"
  tasks:
- debug:
var: l|type_debug
- debug:
var: l.0

gives (abridged)

  l|type_debug: list
  l.0: /First Datacenter/vm/Prod-SRM

But, the code in your first email shows you get *vm_facts* as
registered output of *community.vmware.vmware_guest_find*. Take a
look at the Return Values of this module
https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_guest_find_module.html#return-values

The documentation says *folders* is "list/elements=string". In this
case, no conversion is needed to get the element of the list. For
example,

shell> cat pb2.yml
- hosts: all
  vars:
vm_facts:
  folders: ['/First Datacenter/vm/Prod-SRM']
  tasks:
- debug:
var: vm_facts.folders|type_debug
- debug:
var: vm_facts.folders.0

gives (abridged)

  vm_facts.folders|type_debug: list
  vm_facts.folders.0: /First Datacenter/vm/Prod-SRM

FWIW, try community.general.yaml callback. YAML is much easier to
read compared to JSON. See
https://docs.ansible.com/ansible/latest/collections/community/general/yaml_callback.html

--
Vladimir Botka

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20240112212031.226fcc47%40gmail.com.


pgp6fmFkZQx4i.pgp
Description: OpenPGP digital signature


Re: [ansible-project] Trying to replace single quote with regex_replace

2024-01-12 Thread Dimitri Yioulos
Thanks, Vladimir. Forgive my stupidity but, for my edification, how is that 
actually written in the playbook?

On Wednesday, January 10, 2024 at 12:24:40 PM UTC-5 Rowe, Walter P. (Fed) 
wrote:

> Even better! Brilliant!
>
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services Division
> Mobile: 202.355.4123 <(202)%20355-4123> 
>
> On Jan 10, 2024, at 12:16 PM, Vladimir Botka  wrote:
>
> "['/First Datacenter/vm/Prod-SRM']"
> The problem is [' and ']. They can't be part pf the folder name.
>
>
> FWIW, convert the string to a list
>
> s: "['/First Datacenter/vm/Prod-SRM']"
> l: "{{ s|from_yaml }}"
>
> gives
>
> l.0: /First Datacenter/vm/Prod-SRM
>
> --
> Vladimir Botka
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to ansible-proje...@googlegroups.com.
>
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/20240110181644.79b47b90%40gmail.com
> .
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/d4a87398-b2cc-48f5-872f-01f53f41683an%40googlegroups.com.


[ansible-project] trying to debug ansible and win_package

2024-01-12 Thread Divan Santana
Hi,

I'm trying to debug a ansible windows issue, if someone with powershell
knowledge could help me debug it, it would be great.

I can successfully win_ping win_setup the windows 2019SE server, but not
win_package install or install using chocolatey.  No idea why.

I have this piece of ansible code, to install a package via win_package.

  - name: Ensure 7-Zip is installed through win_package
win_package:
  path: C:\temp\7z.exe
  state: present

The above fails with:

  The win_package action failed to execute in the expected time frame (5) and 
was terminated.

I run my playbook with -v, I see this[1] in the output.  I believe
to debug this further I need to run the powershell script on the windows
box directly.  I'm not quite sure how to do that.  What I've done is
enable powershell script block logging, so that I can decode the
EncodedCommand string (not sure how else to decode it?).  Looking at the
Event Viewer, I can see that the powershell script block is this[2].

I'm rather clueless with powershell.  I'm now stuck at, how can I
execute this powershell script block[2] in the same manner as ansible is
doing it, to see why it's failing to install?  Currently I take the
scriptblock[2] as is and paste it in powershell which simply returns
nothing to the screen.

Any help would be appreciated.  Version details in [3].


[1]:
Using module file 
/home/opc/.ansible/collections/ansible_collections/ansible/windows/plugins/modules/win_package.ps1
Pipelining is enabled.
<10.20.100.184> ESTABLISH WINRM CONNECTION FOR USER: opc on PORT 5986 TO 
10.20.100.184
<10.20.100.184> WINRM CONNECT: transport=credssp 
endpoint=https://10.20.100.184:5986/wsman
<10.20.100.184> WINRM OPEN SHELL: 37E74DAA-A27C-4642-89BB-CDDD11AF95DF
EXEC (via pipeline wrapper)
<10.20.100.184> WINRM EXEC 'PowerShell' ['-NoProfile', '-NonInteractive', 
'-ExecutionPolicy', 'Unrestricted', '-EncodedCommand', 

Re: [ansible-project] Ansible Inventory Plugin

2024-01-12 Thread Brian Coca
either the auto (which will try to find your custom plugin) or your
custom plugin need to be enabled.


-- 
--
Brian Coca (he/him/yo)

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7f%3D1EHW9oakACr7n__NwZm0WcTw9s5gatJdHh1JFiFM5A%40mail.gmail.com.


Re: [ansible-project] Ansible Inventory Plugin

2024-01-12 Thread Kai Pistorius
I found the error. I had to enable the auto and script plugin.

Endre Szabo schrieb am Freitag, 12. Januar 2024 um 14:23:24 UTC+1:

> You don't need to have that Yaml file parsed/verified from within your 
> plugin.
>
> On Fri, Jan 12, 2024 at 04:50:01-0800, Kai Pistorius wrote:
> > I am trying to develop a Ansible Inventory Plugin based on some examples 
> I 
> > found on Github.
> > This is my Yaml File:
> > ---
> > plugin: oracle_inventory
> > oem_db_server: myoem.domain.com
> > oem_db_port: 1521
> > oem_db_sid: OEM
> > oem_schema_owner: SYSMAN
> > oem_owner_password: password
> > oem_target_read_user: READ_ONLY_USER
> > oem_target_read_password: password
> > And this is my implementation of the Plugin:
> > from __future__ import (absolute_import, division, print_function)
> > 
> > from loguru import logger
> > 
> > __metaclass__ = type
> > 
> > DOCUMENTATION = r'''
> > name: oracle_inventory
> > plugin_type: inventory
> > short_description: Returns Ansible inventory from Oracle databases 
> > description: Returns Ansible inventory from Oracle databases which are 
> > registered in Oracle Enterprise Manager (OEM)
> > options:
> > plugin:
> > description: Name of the plugin
> > required: true
> > choices: ['oracle_inventory']
> > oem_db_server:
> > description: The OEM repository database server
> > required: true
> > oem_db_port:
> > description: The Port of the OEM repository database
> > required: true
> > oem_db_sid:
> > description: The ORACLE_SID of the OEM repository database
> > required: true
> > oem_schema_owner:
> > description: The owner of the OEM repository schema
> > required: true
> > oem_owner_password:
> > description: The password of the OEM repository schema owner
> > required: true
> > oem_target_read_user:
> > description: The user which is allowed to query the host, 
> > agent, and database OEM targets and its properties
> > required: true
> > oem_target_read_password:
> > description: The password of the OEM target read user
> > required: true
> > '''
> > 
> > from ansible.plugins.inventory import BaseInventoryPlugin
> > from ansible.errors import AnsibleError, AnsibleParserError
> > 
> > 
> > class InventoryModule(BaseInventoryPlugin):
> > NAME = 'oracle_inventory'
> > 
> > def __init__(self):
> > super(InventoryModule, self).__init__()
> > 
> > def verify_file(self, path):
> > '''Return true/false if this is possibly a valid file for this 
> > plugin to consume
> > '''
> > valid = False
> > if super(InventoryModule, self).verify_file(path):
> > logger.info(path)
> > if path.endswith(('oracle_inventory.yaml',
> > 'oracle_inventory.yml')):
> > valid = True
> > return valid
> > 
> > def parse(self, inventory, loader, path, cache):
> > '''Return dynamic inventory from source '''
> > super(InventoryModule, self).parse(inventory, loader, path, cache)
> > 
> > try:
> > pass
> > # self.oem_db_server = self.get_option("oem_db_server")
> > # self.oem_db_sid = self.get_option("oem_db_port")
> > # self.oem_db_port = self.get_option("oem_db_port")
> > # self.oem_schema_owner = self.get_option("oem_schema_owner")
> > # self.oem_schema_password = 
> > self.get_option("oem_owner_password")
> > # self.oem_target_reader_user = 
> > self.get_option("oem_target_read_user")
> > # self.oem_target_reader_password = 
> > self.get_option("oem_target_read_password")
> > except Exception as e:
> > raise AnsibleError(f"Options required: {e}")
> > self._populate()
> > 
> > def _populate(self):
> > '''Return the hosts and groups'''
> > self.inventory.add_group("MY_DEPARTMENT")
> > self.inventory.add_host(host = "myserver.domain", group=
> > "MY_DEPARTMENT")
> > self.inventory.set_variable("myserver.domain", 'ansible_host', 
> > "myserver.domain")
> > 
> > 
> > Both files are located in /home/kai/inventory_plugins
> > 
> > When I execute 
> > ansible-inventory -vvv -i oracle_inventory.yml --list
> > 
> > I get this warnings:
> > kai@myserver:/home/kai/inventory_plugins:ansible-inventory -vvv -i 
> > oracle_inventory.yml --list
> > ansible-inventory [core 2.16.2]
> > config file = /etc/ansible/ansible.cfg
> > configured module search path = ['/home/kai/.ansible/plugins/modules', 
> > '/usr/share/ansible/plugins/modules']
> > ansible python module location = 
> > /usr/local/lib/python3.11/site-packages/ansible
> > ansible collection location = 
> > /home/kai/.ansible/collections:/usr/share/ansible/collections
> > executable location = /usr/local/bin/ansible-inventory
> > python version = 3.11.0 (main, Apr 4 2023, 13:20:21) [GCC 4.8.5] 
> > (/usr/local/bin/python3.11)
> > jinja version = 3.1.2
> > libyaml = True
> > Using /etc/ansible/ansible.cfg as config file
> > redirecting (type: inventory) ansible.builtin.virtualbox to 
> > community.general.virtualbox
> > host_list declined parsing 
> /home/kai/inventory_plugins/oracle_inventory.yml 
> > as it did not pass its verify_file() method
> > ansible_collections.community.general.plugins.inventory.virtualbox 
> declined 
> > parsing 

Re: [ansible-project] Ansible Inventory Plugin

2024-01-12 Thread Endre Szabo
You don't need to have that Yaml file parsed/verified from within your plugin.

On Fri, Jan 12, 2024 at 04:50:01-0800, Kai Pistorius wrote:
> I am trying to develop a Ansible Inventory Plugin based on some examples I 
> found on Github.
> This is my Yaml File:
> ---
> plugin: oracle_inventory
> oem_db_server: myoem.domain.com
> oem_db_port: 1521
> oem_db_sid: OEM
> oem_schema_owner: SYSMAN
> oem_owner_password: password
> oem_target_read_user: READ_ONLY_USER
> oem_target_read_password: password
> And this is my implementation of the Plugin:
> from __future__ import (absolute_import, division, print_function)
> 
> from loguru import logger
> 
> __metaclass__ = type
> 
> DOCUMENTATION = r'''
> name: oracle_inventory
> plugin_type: inventory
> short_description: Returns Ansible inventory from Oracle databases 
> description: Returns Ansible inventory from Oracle databases which are 
> registered in Oracle Enterprise Manager (OEM)
> options:
> plugin:
> description: Name of the plugin
> required: true
> choices: ['oracle_inventory']
> oem_db_server:
> description: The OEM repository database server
> required: true
> oem_db_port:
> description: The Port of the OEM repository database
> required: true
> oem_db_sid:
> description: The ORACLE_SID of the OEM repository database
> required: true
> oem_schema_owner:
> description: The owner of the OEM repository schema
> required: true
> oem_owner_password:
> description: The password of the OEM repository schema owner
> required: true
> oem_target_read_user:
> description: The user which is allowed to query the host, 
> agent, and database OEM targets and its properties
> required: true
> oem_target_read_password:
> description: The password of the OEM target read user
> required: true
> '''
> 
> from ansible.plugins.inventory import BaseInventoryPlugin
> from ansible.errors import AnsibleError, AnsibleParserError
> 
> 
> class InventoryModule(BaseInventoryPlugin):
> NAME = 'oracle_inventory'
> 
> def __init__(self):
> super(InventoryModule, self).__init__()
> 
> def verify_file(self, path):
> '''Return true/false if this is possibly a valid file for this 
> plugin to consume
> '''
> valid = False
> if super(InventoryModule, self).verify_file(path):
> logger.info(path)
> if path.endswith(('oracle_inventory.yaml',
>   'oracle_inventory.yml')):
> valid = True
> return valid
> 
> def parse(self, inventory, loader, path, cache):
> '''Return dynamic inventory from source '''
> super(InventoryModule, self).parse(inventory, loader, path, cache)
> 
> try:
> pass
> # self.oem_db_server = self.get_option("oem_db_server")
> # self.oem_db_sid = self.get_option("oem_db_port")
> # self.oem_db_port = self.get_option("oem_db_port")
> # self.oem_schema_owner = self.get_option("oem_schema_owner")
> # self.oem_schema_password = 
> self.get_option("oem_owner_password")
> # self.oem_target_reader_user = 
> self.get_option("oem_target_read_user")
> # self.oem_target_reader_password = 
> self.get_option("oem_target_read_password")
> except Exception as e:
> raise AnsibleError(f"Options required: {e}")
> self._populate()
> 
> def _populate(self):
> '''Return the hosts and groups'''
> self.inventory.add_group("MY_DEPARTMENT")
> self.inventory.add_host(host = "myserver.domain", group=
> "MY_DEPARTMENT")
> self.inventory.set_variable("myserver.domain", 'ansible_host', 
> "myserver.domain")
> 
> 
> Both files are located in /home/kai/inventory_plugins
> 
> When I execute 
> ansible-inventory -vvv -i oracle_inventory.yml --list
> 
> I get this warnings:
> kai@myserver:/home/kai/inventory_plugins:ansible-inventory -vvv -i 
> oracle_inventory.yml --list
> ansible-inventory [core 2.16.2]
>   config file = /etc/ansible/ansible.cfg
>   configured module search path = ['/home/kai/.ansible/plugins/modules', 
> '/usr/share/ansible/plugins/modules']
>   ansible python module location = 
> /usr/local/lib/python3.11/site-packages/ansible
>   ansible collection location = 
> /home/kai/.ansible/collections:/usr/share/ansible/collections
>   executable location = /usr/local/bin/ansible-inventory
>   python version = 3.11.0 (main, Apr  4 2023, 13:20:21) [GCC 4.8.5] 
> (/usr/local/bin/python3.11)
>   jinja version = 3.1.2
>   libyaml = True
> Using /etc/ansible/ansible.cfg as config file
> redirecting (type: inventory) ansible.builtin.virtualbox to 
> community.general.virtualbox
> host_list declined 

[ansible-project] Ansible Inventory Plugin

2024-01-12 Thread Kai Pistorius
I am trying to develop a Ansible Inventory Plugin based on some examples I 
found on Github.
This is my Yaml File:
---
plugin: oracle_inventory
oem_db_server: myoem.domain.com
oem_db_port: 1521
oem_db_sid: OEM
oem_schema_owner: SYSMAN
oem_owner_password: password
oem_target_read_user: READ_ONLY_USER
oem_target_read_password: password
And this is my implementation of the Plugin:
from __future__ import (absolute_import, division, print_function)

from loguru import logger

__metaclass__ = type

DOCUMENTATION = r'''
name: oracle_inventory
plugin_type: inventory
short_description: Returns Ansible inventory from Oracle databases 
description: Returns Ansible inventory from Oracle databases which are 
registered in Oracle Enterprise Manager (OEM)
options:
plugin:
description: Name of the plugin
required: true
choices: ['oracle_inventory']
oem_db_server:
description: The OEM repository database server
required: true
oem_db_port:
description: The Port of the OEM repository database
required: true
oem_db_sid:
description: The ORACLE_SID of the OEM repository database
required: true
oem_schema_owner:
description: The owner of the OEM repository schema
required: true
oem_owner_password:
description: The password of the OEM repository schema owner
required: true
oem_target_read_user:
description: The user which is allowed to query the host, 
agent, and database OEM targets and its properties
required: true
oem_target_read_password:
description: The password of the OEM target read user
required: true
'''

from ansible.plugins.inventory import BaseInventoryPlugin
from ansible.errors import AnsibleError, AnsibleParserError


class InventoryModule(BaseInventoryPlugin):
NAME = 'oracle_inventory'

def __init__(self):
super(InventoryModule, self).__init__()

def verify_file(self, path):
'''Return true/false if this is possibly a valid file for this 
plugin to consume
'''
valid = False
if super(InventoryModule, self).verify_file(path):
logger.info(path)
if path.endswith(('oracle_inventory.yaml',
  'oracle_inventory.yml')):
valid = True
return valid

def parse(self, inventory, loader, path, cache):
'''Return dynamic inventory from source '''
super(InventoryModule, self).parse(inventory, loader, path, cache)

try:
pass
# self.oem_db_server = self.get_option("oem_db_server")
# self.oem_db_sid = self.get_option("oem_db_port")
# self.oem_db_port = self.get_option("oem_db_port")
# self.oem_schema_owner = self.get_option("oem_schema_owner")
# self.oem_schema_password = 
self.get_option("oem_owner_password")
# self.oem_target_reader_user = 
self.get_option("oem_target_read_user")
# self.oem_target_reader_password = 
self.get_option("oem_target_read_password")
except Exception as e:
raise AnsibleError(f"Options required: {e}")
self._populate()

def _populate(self):
'''Return the hosts and groups'''
self.inventory.add_group("MY_DEPARTMENT")
self.inventory.add_host(host = "myserver.domain", group=
"MY_DEPARTMENT")
self.inventory.set_variable("myserver.domain", 'ansible_host', 
"myserver.domain")


Both files are located in /home/kai/inventory_plugins

When I execute 
ansible-inventory -vvv -i oracle_inventory.yml --list

I get this warnings:
kai@myserver:/home/kai/inventory_plugins:ansible-inventory -vvv -i 
oracle_inventory.yml --list
ansible-inventory [core 2.16.2]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/kai/.ansible/plugins/modules', 
'/usr/share/ansible/plugins/modules']
  ansible python module location = 
/usr/local/lib/python3.11/site-packages/ansible
  ansible collection location = 
/home/kai/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-inventory
  python version = 3.11.0 (main, Apr  4 2023, 13:20:21) [GCC 4.8.5] 
(/usr/local/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True
Using /etc/ansible/ansible.cfg as config file
redirecting (type: inventory) ansible.builtin.virtualbox to 
community.general.virtualbox
host_list declined parsing /home/kai/inventory_plugins/oracle_inventory.yml 
as it did not pass its verify_file() method
ansible_collections.community.general.plugins.inventory.virtualbox declined 
parsing /home/kai/inventory_plugins/oracle_inventory.yml as it did not pass 
its verify_file() method
[WARNING]:  * Failed to parse 
/home/kai/inventory_plugins/oracle_inventory.yml with yaml plugin: Plugin 
configuration