Re: [ansible-project] Need help in AWX credential "Hushicorp vault signed SSH

2024-09-11 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
Please go to the ansible forums website and pose your question. This mailing 
list will close soon.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Sep 11, 2024, at 8:45 AM, Thirumalai Raja A  
wrote:

Hi Everyone,

I am using AWX tower to patch a linux VM and using Hushicorp vault signed SSH 
for connecting to all our linux vm. gathering facts is working and in my task i 
have performing pre-patch reboot after my vm got restart vm got disconnected 
error is "timeout waiting for last boot time"

can any one guide me on this if I need any config from my AWX tower side.

Regards,
Thirumalai.

--
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 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CALyK%3Dg-3%2B%3D8YOH4xTRdCNyOewh4%3DZBw6Tix-W%2BPSS2n9%3Dg0PmA%40mail.gmail.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CBCC250C-45CD-4B9F-828D-A1ED2DBDE475%40nist.gov.


Re: [ansible-project]

2024-09-04 Thread Todd Lewis

Hello Alex,

That error looks very much like the original error. I don't have vmware 
snapshots I can play with, so I (and I presume Stephen Maher) are 
limited to throwing suggestions over the wall so to speak.


Anyway, my guess is that your creation_time is some complex type - well, 
more complex than a string anyway, while our Jinja expressions are 
limited to producing strings. I would be curious to know what "| 
type_debug" after your creation_time produces. It should show the type 
of the preceding expression. In any case, I don't think your `old_date` 
ends up being a datetime object since Jinja produces strings. The "| 
to_datetime" part "wares off" so to speak once the expression is 
resolved, and you end up with a string. Behold:


utoddl@tango:~/ansible$  *cat test.yml*
---
# test.yml
- name: Date games
  hosts: localhost
  gather_facts: false
  vars:
old_date: "{{ lookup('ansible.builtin.pipe', 'date -d \"now - 14 days\" 
+%Y-%m-%dT%H:%M:%S') }}"
start_trigger: "{{ (now(utc=false,fmt='%Y-%m-%dT%H:%M:%S') | 
to_datetime('%Y-%m-%dT%H:%M:%S')).strftime('%s') }}"
  tasks:
- name: Set 2 weeks ago date
  ansible.builtin.set_fact:
new_date: "{{ lookup('ansible.builtin.pipe', 'date -d \"now - 14 days\" 
+%Y-%m-%d\" \"%H:%M:%S') | to_datetime }}"
- name: Check types
  ansible.builtin.debug:
msg:
 - '{{ old_date }}, {{ old_date | type_debug }}'
 - '{{ new_date }}, {{ new_date | type_debug }}'
utoddl@tango:~/ansible$  *ansible-playbook test.yml*

PLAY [Date games] 
*

TASK [Set 2 weeks ago date] 
***
ok: [localhost]

TASK [Check types] 

ok: [localhost] =>
  msg:
  - 2024-08-21T23:56:21, AnsibleUnsafeText
  - 2024-08-21 23:56:21, AnsibleUnsafeText

Since the output of `date` is a string, if you could get `create_time` 
to be a string also, you could compare them as strings rather than 
datetime objects. And you probably only need the "+%Y-%m-%d" part anyway.


On 9/4/24 7:29 PM, Alex Wanderley wrote:

Hello Todd,

After a slight change on your suggestion (space, instead of 
"T": +%Y-%m-%d\" \"%H:%M:%S), I could have "old_date" as a time object:

 - name: Set 2 weeks ago date
  ansible.builtin.set_fact:
      old_date: "{{ lookup('ansible.builtin.pipe', 'date -d \"now - 14 
days\" +%Y-%m-%d\" \"%H:%M:%S') | to_datetime }}"


So, now I can use that in Stephen's suggestion:
     - name: Filter snapshots older than 2 weeks
       ansible.builtin.set_fact:
           old_snapshots: "{{ snapshots_info.vmware_all_snapshots_info 
| selectattr('vm_name', 'select', '(creation_time <= old_date') }}"


But that is still erroring out:
TASK [Filter snapshots older than 2 weeks] 
*
An exception occurred during task execution. To see the full 
traceback, use -vvv. The error was: line 0

fatal: [localhost]: FAILED! => {"changed": false}

I'm very grateful for all your help, but I don't intend to consume 
much more of your time with my problem. So, one last question if you 
don't mind:
Would I be able to convert "creation_time" which is a string like 
"2024-05-26T10:01:21.219280+00:00" into a date/time object formatted 
as "old_date" mentioned up above? (As I think that the error is 
related to me trying to compare a string to a date/time object.)


Note: "creation_time | to_datetime" does not work. As, in short, it 
gave me:
"... The error was: time data '2024-05-26T10:01:21.219280+00:00' does 
not match format '%Y-%m-%d %H:%M:%S'\n\n..."


Again, thank you...

Alex
On Wed, Sep 4, 2024 at 2:30 PM Todd Lewis  wrote:

If you don't havenow(), you can probably use this:

old_date: "{{ lookup('ansible.builtin.pipe', 'date -d \"now - 14 days\" 
+%Y-%m-%dT%H:%M:%S') }}"



On 9/4/24 4:05 PM, Alex Wanderley wrote:

Hi Stephen,

First of all, thanks for helping...
(Long read ahead, sorry.)

I'm afraid that did not work for me.

I'm collecting all the snapshots using
"community.vmware.vmware_all_snapshots_info":
- name: Collect snapshots older than 2 weeks
community.vmware.vmware_all_snapshots_info:
       datacenter: "{{ datacenter_name }}"
       validate_certs: false
  register: snapshots_info

Which does not return "snapshots_info.virtual_machines". Instead,
it returns "snapshots_info.vmware_all_snapshots_info"So, I had to
adjust your suggestion to:
     - name: Filter snapshots older than 2 weeks
       ansible.builtin.set_fact:
           old_snapshots: "{{
snapshots_info.vmware_all_snapshots_info | selectattr('vm_name',
'defined') | selectattr('vm_name', 'select', 'creation_time <=
old_date') }}"
       vars:
           old_date: "{{ 

Re: [ansible-project]

2024-09-04 Thread Alex Wanderley
Hello Todd,

After a slight change on your suggestion (space, instead of
"T": +%Y-%m-%d\" \"%H:%M:%S), I could have "old_date" as a time object:
 - name: Set 2 weeks ago date
  ansible.builtin.set_fact:
  old_date: "{{ lookup('ansible.builtin.pipe', 'date -d \"now - 14
days\" +%Y-%m-%d\" \"%H:%M:%S') | to_datetime }}"

So, now I can use that in Stephen's suggestion:
 - name: Filter snapshots older than 2 weeks
   ansible.builtin.set_fact:
   old_snapshots: "{{ snapshots_info.vmware_all_snapshots_info |
selectattr('vm_name', 'select', '(creation_time <= old_date') }}"

But that is still erroring out:
TASK [Filter snapshots older than 2 weeks]
*
An exception occurred during task execution. To see the full traceback, use
-vvv. The error was: line 0
fatal: [localhost]: FAILED! => {"changed": false}

I'm very grateful for all your help, but I don't intend to consume much
more of your time with my problem. So, one last question if you don't mind:
Would I be able to convert "creation_time" which is a string like
"2024-05-26T10:01:21.219280+00:00"
into a date/time object formatted as "old_date" mentioned up above? (As I
think that the error is related to me trying to compare a string to a
date/time object.)

Note: "creation_time | to_datetime" does not work. As, in short, it gave me:
"... The error was: time data '2024-05-26T10:01:21.219280+00:00' does not
match format '%Y-%m-%d %H:%M:%S'\n\n..."

Again, thank you...

Alex
On Wed, Sep 4, 2024 at 2:30 PM Todd Lewis  wrote:

> If you don't have now(), you can probably use this:
>
> old_date: "{{ lookup('ansible.builtin.pipe', 'date -d \"now - 14 days\" 
> +%Y-%m-%dT%H:%M:%S') }}"
>
>
>
> On 9/4/24 4:05 PM, Alex Wanderley wrote:
>
> Hi Stephen,
>
> First of all, thanks for helping...
> (Long read ahead, sorry.)
>
> I'm afraid that did not work for me.
>
> I'm collecting all the snapshots using
> "community.vmware.vmware_all_snapshots_info":
> - name: Collect snapshots older than 2 weeks
>   community.vmware.vmware_all_snapshots_info:
>datacenter: "{{ datacenter_name }}"
>validate_certs: false
>   register: snapshots_info
>
> Which does not return "snapshots_info.virtual_machines". Instead, it
> returns "snapshots_info.vmware_all_snapshots_info" So, I had to adjust
> your suggestion to:
>  - name: Filter snapshots older than 2 weeks
>ansible.builtin.set_fact:
>old_snapshots: "{{ snapshots_info.vmware_all_snapshots_info |
> selectattr('vm_name', 'defined') | selectattr('vm_name', 'select',
> 'creation_time <= old_date') }}"
>vars:
>old_date: "{{ (now() -
> timedelta(weeks=2)).strftime('%Y-%m-%dT%H:%M:%S') }}"
>
> But that gave me this:
> TASK [Filter snapshots older than 2 weeks]
> *
> An exception occurred during task execution. To see the full traceback,
> use -vvv. The error was:   line 0
> fatal: [localhost]: FAILED! => {"changed": false}
>
> So, as a test, I tried to define "old_date" separately using:
> - name: Set 2 weeks ago date
>   ansible.builtin.set_fact:
>   old_date: "{{ (now() -
> timedelta(weeks=2)).strftime('%Y-%m-%dT%H:%M:%S') }}"
>
> Which gave me the error below. (That error makes me believe that our
> environment  (AAP 2.4 + Ansible-core 2.15) perhaps is missing something.)
> TASK [Set 2 weeks ago date]
> 
> fatal: [localhost]: FAILED! => {"msg": "The task includes an option with
> an undefined variable. The error was: 'timedelta' is undefined. 'timedelta'
> is undefined\n\nThe error appears to be in
> '/runner/project/dealing_with_snapshots.yml': line 28, column 8, but
> may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe
> offending line appears to be:\n\n\n - name: Set 2 weeks ago date\n
>   ^ here\n"}
>
> When somehow the "timedelta" error is resolved, do you think I'd be able
> to populate the "old_date" variable prior to calling "
> community.vmware.vmware_all_snapshots_info" and then go with something
> like this? (Sorry for my lack of knowledge if what I'm asking is complete
> nonsense...)
> - name: Collect snapshots older than 2 weeks
>   community.vmware.vmware_all_snapshots_info:
>   datacenter: "{{ datacenter_name }}"
>   validate_certs: false
>   filters:
>creation_time: " {{ selectattr('vm_name', 'select', 'creation_time
> <= old_date') }}"
>   register: snapshots_info
>
> The reason I'm bringing back the idea of using "filters" from 
> vmware_all_snapshots_info
> is that it would return a, potentially, much shorter list of VMs for me to
> deal with.
>
> Regards,
>
> Alex
>
> On Wed, Sep 4, 2024 at 1:11 AM Stephen Maher  wrote:
>
>> Alex,
>>
>> Does this wok for you as i’ve previously used something similar.
>>
>> Regards
>>
>>
>>
>> - name: Gather VMs with snapshots older than 2 weeks
>>   hosts: localhost
>>   gather_facts: no
>>   tasks:
>> - name: Get all snapshots info
>>   

Re: [ansible-project]

2024-09-04 Thread Todd Lewis

If you don't havenow(), you can probably use this:

old_date: "{{ lookup('ansible.builtin.pipe', 'date -d \"now - 14 days\" 
+%Y-%m-%dT%H:%M:%S') }}"



On 9/4/24 4:05 PM, Alex Wanderley wrote:

Hi Stephen,

First of all, thanks for helping...
(Long read ahead, sorry.)

I'm afraid that did not work for me.

I'm collecting all the snapshots using 
"community.vmware.vmware_all_snapshots_info":

- name: Collect snapshots older than 2 weeks
  community.vmware.vmware_all_snapshots_info:
       datacenter: "{{ datacenter_name }}"
       validate_certs: false
  register: snapshots_info

Which does not return "snapshots_info.virtual_machines". Instead, it 
returns "snapshots_info.vmware_all_snapshots_info"So, I had to adjust 
your suggestion to:

     - name: Filter snapshots older than 2 weeks
       ansible.builtin.set_fact:
           old_snapshots: "{{ snapshots_info.vmware_all_snapshots_info 
| selectattr('vm_name', 'defined') | selectattr('vm_name', 'select', 
'creation_time <= old_date') }}"

       vars:
           old_date: "{{ (now() - 
timedelta(weeks=2)).strftime('%Y-%m-%dT%H:%M:%S') }}"


But that gave me this:
TASK [Filter snapshots older than 2 weeks] 
*
An exception occurred during task execution. To see the full 
traceback, use -vvv. The error was:   line 0

fatal: [localhost]: FAILED! => {"changed": false}

So, as a test, I tried to define "old_date" separately using:
- name: Set 2 weeks ago date
  ansible.builtin.set_fact:
          old_date: "{{ (now() - 
timedelta(weeks=2)).strftime('%Y-%m-%dT%H:%M:%S') }}"


Which gave me the error below. (That error makes me believe that our 
environment  (AAP 2.4 + Ansible-core 2.15) perhaps is missing something.)
TASK [Set 2 weeks ago date] 

fatal: [localhost]: FAILED! => {"msg": "The task includes an option 
with an undefined variable. The error was: 'timedelta' is undefined. 
'timedelta' is undefined\n\nThe error appears to be in 
'/runner/project/dealing_with_snapshots.yml': line 28, column 8, but 
may\nbe elsewhere in the file depending on the exact syntax 
problem.\n\nThe offending line appears to be:\n\n\n     - name: Set 2 
weeks ago date\n       ^ here\n"}


When somehow the "timedelta" error is resolved, do you think I'd be 
able to populate the "old_date" variable prior to calling" 
community.vmware.vmware_all_snapshots_info" and then go with something 
like this? (Sorry for my lack of knowledge if what I'm asking is 
complete nonsense...)

- name: Collect snapshots older than 2 weeks
  community.vmware.vmware_all_snapshots_info:
  datacenter: "{{ datacenter_name }}"
  validate_certs: false
  filters:
       creation_time: " {{ selectattr('vm_name', 'select', 
'creation_time <= old_date') }}"

  register: snapshots_info

The reason I'm bringing back the idea of using "filters" from 
vmware_all_snapshots_info is that it would return a, potentially, much 
shorter list of VMs for me to deal with.


Regards,

Alex

On Wed, Sep 4, 2024 at 1:11 AM Stephen Maher  wrote:

Alex,

Does this wok for you as i’ve previously used something similar.

Regards



- name: Gather VMs with snapshots older than 2 weeks
  hosts: localhost
  gather_facts: no
  tasks:
    - name: Get all snapshots info
      community.vmware.vmware_all_snapshots_info:
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        validate_certs: no
      register: snapshots_info

    - name: Filter snapshots older than 2 weeks
      set_fact:
        old_snapshots: "{{ snapshots_info.virtual_machines |
selectattr('snapshots', 'defined') | selectattr('snapshots',
'select', 'creation_time <= old_date') }}"
      vars:
        old_date: "{{ (now() -
timedelta(weeks=2)).strftime('%Y-%m-%dT%H:%M:%S') }}"

    - name: Display VMs with snapshots older than 2 weeks
      debug:
        var: old_snapshots



On 4 Sep 2024, at 03:37, Alex Wanderley
 wrote:

Hi,

I've been trying to solve this but I truly still have lots to
learn... Could somebody help?

Given that a VM "creation_time" snapshot property has this
format: "2024-05-26T10:01:21.219280+00:00".

How could I build a filter for the
"community.vmware.vmware_all_snapshots_info" module that would
give me VMs whose snapshots were created 2 weeks ago or older?

     - name: Collect snapshots older than 2 weeks
 community.vmware.vmware_all_snapshots_info:
           datacenter: "{{ datacenter_name }}"
           validate_certs: false
           filters:
               creation_time: ""
               match_type: includes
       register: old_snapshots

Thanks...

Alex


-- 
You received this message because you are subscribed to the

Google Groups "Ansible Project" group.
To unsubscribe 

Re: [ansible-project]

2024-09-04 Thread Alex Wanderley
Hi Stephen,

First of all, thanks for helping...
(Long read ahead, sorry.)

I'm afraid that did not work for me.

I'm collecting all the snapshots using
"community.vmware.vmware_all_snapshots_info":
- name: Collect snapshots older than 2 weeks
  community.vmware.vmware_all_snapshots_info:
   datacenter: "{{ datacenter_name }}"
   validate_certs: false
  register: snapshots_info

Which does not return "snapshots_info.virtual_machines". Instead, it
returns "snapshots_info.vmware_all_snapshots_info" So, I had to adjust your
suggestion to:
 - name: Filter snapshots older than 2 weeks
   ansible.builtin.set_fact:
   old_snapshots: "{{ snapshots_info.vmware_all_snapshots_info |
selectattr('vm_name', 'defined') | selectattr('vm_name', 'select',
'creation_time <= old_date') }}"
   vars:
   old_date: "{{ (now() -
timedelta(weeks=2)).strftime('%Y-%m-%dT%H:%M:%S') }}"

But that gave me this:
TASK [Filter snapshots older than 2 weeks]
*
An exception occurred during task execution. To see the full traceback, use
-vvv. The error was:   line 0
fatal: [localhost]: FAILED! => {"changed": false}

So, as a test, I tried to define "old_date" separately using:
- name: Set 2 weeks ago date
  ansible.builtin.set_fact:
  old_date: "{{ (now() -
timedelta(weeks=2)).strftime('%Y-%m-%dT%H:%M:%S') }}"

Which gave me the error below. (That error makes me believe that our
environment  (AAP 2.4 + Ansible-core 2.15) perhaps is missing something.)
TASK [Set 2 weeks ago date]

fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an
undefined variable. The error was: 'timedelta' is undefined. 'timedelta' is
undefined\n\nThe error appears to be in
'/runner/project/dealing_with_snapshots.yml': line 28, column 8, but
may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe
offending line appears to be:\n\n\n - name: Set 2 weeks ago date\n
  ^ here\n"}

When somehow the "timedelta" error is resolved, do you think I'd be able to
populate the "old_date" variable prior to calling "
community.vmware.vmware_all_snapshots_info" and then go with something like
this? (Sorry for my lack of knowledge if what I'm asking is complete
nonsense...)
- name: Collect snapshots older than 2 weeks
  community.vmware.vmware_all_snapshots_info:
  datacenter: "{{ datacenter_name }}"
  validate_certs: false
  filters:
   creation_time: " {{ selectattr('vm_name', 'select', 'creation_time
<= old_date') }}"
  register: snapshots_info

The reason I'm bringing back the idea of using "filters" from
vmware_all_snapshots_info
is that it would return a, potentially, much shorter list of VMs for me to
deal with.

Regards,

Alex

On Wed, Sep 4, 2024 at 1:11 AM Stephen Maher  wrote:

> Alex,
>
> Does this wok for you as i’ve previously used something similar.
>
> Regards
>
>
>
> - name: Gather VMs with snapshots older than 2 weeks
>   hosts: localhost
>   gather_facts: no
>   tasks:
> - name: Get all snapshots info
>   community.vmware.vmware_all_snapshots_info:
> hostname: "{{ vcenter_hostname }}"
> username: "{{ vcenter_username }}"
> password: "{{ vcenter_password }}"
> validate_certs: no
>   register: snapshots_info
>
> - name: Filter snapshots older than 2 weeks
>   set_fact:
> old_snapshots: "{{ snapshots_info.virtual_machines |
> selectattr('snapshots', 'defined') | selectattr('snapshots', 'select',
> 'creation_time <= old_date') }}"
>   vars:
> old_date: "{{ (now() -
> timedelta(weeks=2)).strftime('%Y-%m-%dT%H:%M:%S') }}"
>
> - name: Display VMs with snapshots older than 2 weeks
>   debug:
> var: old_snapshots
>
>
> On 4 Sep 2024, at 03:37, Alex Wanderley 
> wrote:
>
> Hi,
>
> I've been trying to solve this but I truly still have lots to learn...
> Could somebody help?
>
> Given that a VM "creation_time" snapshot property has this format:
> "2024-05-26T10:01:21.219280+00:00".
>
> How could I build a filter for the
> "community.vmware.vmware_all_snapshots_info" module that would give me VMs
> whose snapshots were created 2 weeks ago or older?
>
>  - name: Collect snapshots older than 2 weeks
>community.vmware.vmware_all_snapshots_info:
>datacenter: "{{ datacenter_name }}"
>validate_certs: false
>filters:
>creation_time: ""
>match_type: includes
>register: old_snapshots
>
> Thanks...
>
> Alex
>
>
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CADp8UUS10CbPWP45TRpfXB%2BYRWev5KaSRFjchAi7KQO7Dt%2BzHQ%40mail.gmail.com
> 

Re: [ansible-project]

2024-09-04 Thread Stephen Maher
Alex,

Does this wok for you as i’ve previously used something similar.

Regards



- name: Gather VMs with snapshots older than 2 weeks
  hosts: localhost
  gather_facts: no
  tasks:
- name: Get all snapshots info
  community.vmware.vmware_all_snapshots_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
  register: snapshots_info

- name: Filter snapshots older than 2 weeks
  set_fact:
old_snapshots: "{{ snapshots_info.virtual_machines | 
selectattr('snapshots', 'defined') | selectattr('snapshots', 'select', 
'creation_time <= old_date') }}"
  vars:
old_date: "{{ (now() - 
timedelta(weeks=2)).strftime('%Y-%m-%dT%H:%M:%S') }}"

- name: Display VMs with snapshots older than 2 weeks
  debug:
var: old_snapshots


> On 4 Sep 2024, at 03:37, Alex Wanderley  wrote:
> 
> Hi,
> 
> I've been trying to solve this but I truly still have lots to learn... Could 
> somebody help?
> 
> Given that a VM "creation_time" snapshot property has this format: 
> "2024-05-26T10:01:21.219280+00:00".
> 
> How could I build a filter for the 
> "community.vmware.vmware_all_snapshots_info" module that would give me VMs 
> whose snapshots were created 2 weeks ago or older?
> 
>  - name: Collect snapshots older than 2 weeks
>community.vmware.vmware_all_snapshots_info:
>datacenter: "{{ datacenter_name }}"
>validate_certs: false
>filters:
>creation_time: ""
>match_type: includes
>register: old_snapshots
> 
> Thanks...
> 
> Alex
> 
>  
> 
> 
> The contents of this message and any attachment(s) are confidential, 
> proprietary to the City of Edmonton, and are intended only for the addressed 
> recipient. If you have received this in error, please disregard the contents, 
> inform the sender of the misdirection, and remove it from your system. The 
> copying, dissemination, or distribution of this message, if misdirected, is 
> strictly prohibited.
> 
> -- 
> 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 [email protected] 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/CADp8UUS10CbPWP45TRpfXB%2BYRWev5KaSRFjchAi7KQO7Dt%2BzHQ%40mail.gmail.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6F27360B-C585-4887-A1DF-230B8C3020A0%40gmail.com.


Re: [ansible-project] list of lists, to list of dicts?

2024-08-29 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
Thanks Todd. Honestly I came right off the dict module page that has an almost 
exact example.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Aug 29, 2024, at 8:34 AM, Todd Lewis  wrote:

That is elegant. Much better than the abomination I came up with:

---
# dick-visser-03.yml
- name: Add helper keys to list of dicts
  hosts: localhost
  connection: local
  gather_facts: no
  vars:
test:
  - - host1
- fd99:::1
  - - host1
- 10.0.1.1
  - - host2
- fd99:::1
  - - host2
- 10.0.1.1
  - - foo
- fd99:::1
  - - foo
- 10.0.1.1
  - - baz
- fd99:::1
  - - baz
- 10.0.1.1
  tasks:
- name: Dictify the test data - 1
  ansible.builtin.debug:
msg:
  - 'test'
  - '{{ test }}'

  - '   test | map("map","community.general.dict_kv","value")'
  - '{{ test | map("map","community.general.dict_kv","value") }}'

  - '   test | map("map","community.general.dict_kv","value") | 
map("zip",[{"key":"name"},{"key":"address"}])'
  - '{{ test | map("map","community.general.dict_kv","value") | 
map("zip",[{"key":"name"},{"key":"address"}]) }}'

  - '   test
| map("map","community.general.dict_kv","value")
| map("zip",[{"key":"name"},{"key":"address"}])
| map("map","flatten",1)
| map("map","combine")'
  - '{{ test
| map("map","community.general.dict_kv","value")
| map("zip",[{"key":"name"},{"key":"address"}])
| map("map","flatten",1)
| map("map","combine") }}'

  - '   test
| map("map","community.general.dict_kv","value")
| map("zip",[{"key":"name"},{"key":"address"}])
| map("map","flatten",1)
| map("map","combine")
| map("items2dict")'
  - '{{ test
| map("map","community.general.dict_kv","value")
| map("zip",[{"key":"name"},{"key":"address"}])
| map("map","flatten",1)
| map("map","combine")
| map("items2dict") }}'


On 8/29/24 7:38 AM, 'Rowe, Walter P. (Fed)' via Ansible Project wrote:
https://docs.ansible.com/ansible/latest/collections/community/general/dict_filter.html

This is an even more elegant solution using the community.general.dict module:


- name: list2dict
  set_fact:
list2dict: >-
  {{ test | map('zip', ['name', 'addr'])
| map('map', 'reverse')
| map('community.general.dict') }}

- name: list2dict
  debug: var=list2dict



Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Aug 29, 2024, at 7:22 AM, Rowe, Walter P. (Fed) 
 wrote:



- name: list of list to list of dict
  hosts: localhost
  become: false
  gather_facts: false
  vars:
test:
  - - host1
- fd99:::1
  - - host1
- 10.0.1.1
  - - host2
- fd99:::1
  - - host2
- 10.0.1.1
  - - foo
- fd99:::1
  - - foo
- 10.0.1.1
  - - baz
- fd99:::1
  - - baz
- 10.0.1.1
  tasks:
- name: test
  debug: var=test

- name: list 2 dict
  set_fact:
list2dict: "{{ list2dict|default([]) + [ thisdict ] }}"
  loop: "{{ test }}"
  vars:
thisdict: { name: "{{ item.0 }}", addr: "{{ item.1 }}" }

- name: list2dict
  debug: var=list2dict




Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Aug 29, 2024, at 5:40 AM, Dick Visser 
 wrote:

Hii

I have something like this in my vars:

test:
  - - host1
- fd99:::1
  - - host1
- 10.0.1.1
  - - host2
- fd99:::1
  - - host2
- 10.0.1.1
  - - foo
- fd99:::1
  - - foo
- 10.0.1.1
  - - baz
- fd99:::1
  - - baz
- 10.0.1.1


Each first and second list item should become keys in a dict, like this:

conv:
  - name: host1
address: fd99:::1
  - name: host1
address: 10.0.1.1
  - name: host2
address: fd99:::1
  - name: host2
address: 10.0.1.1
  - name: foo
address: fd99:::1
  - name: foo
address: 10.0.1.1
  - name: baz
address: fd99:::1
  - name: baz
address: 10.0.1.1

I tried a few things with mapping and filtering, but can't see how to do it
any suggestions? Ideally no tasks, just filters

thx




--
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 
[email protected].
To view this discussion on the web visit 

Re: [ansible-project] list of lists, to list of dicts?

2024-08-29 Thread Todd Lewis

That is elegant. Much better than the abomination I came up with:

---
# dick-visser-03.yml
- name: Add helper keys to list of dicts
  hosts: localhost
  connection: local
  gather_facts: no
  vars:
test:
  - - host1
- fd99:::1
  - - host1
- 10.0.1.1
  - - host2
- fd99:::1
  - - host2
- 10.0.1.1
  - - foo
- fd99:::1
  - - foo
- 10.0.1.1
  - - baz
- fd99:::1
  - - baz
- 10.0.1.1
  tasks:
- name: Dictify the test data - 1
  ansible.builtin.debug:
msg:
  - 'test'
  - '{{ test }}'

  - '   test | map("map","community.general.dict_kv","value")'
  - '{{ test | map("map","community.general.dict_kv","value") }}'

  - '   test | map("map","community.general.dict_kv","value") | 
map("zip",[{"key":"name"},{"key":"address"}])'
  - '{{ test | map("map","community.general.dict_kv","value") | 
map("zip",[{"key":"name"},{"key":"address"}]) }}'

  - '   test
| map("map","community.general.dict_kv","value")
| map("zip",[{"key":"name"},{"key":"address"}])
| map("map","flatten",1)
| map("map","combine")'
  - '{{ test
| map("map","community.general.dict_kv","value")
| map("zip",[{"key":"name"},{"key":"address"}])
| map("map","flatten",1)
| map("map","combine") }}'

  - '   test
| map("map","community.general.dict_kv","value")
| map("zip",[{"key":"name"},{"key":"address"}])
| map("map","flatten",1)
| map("map","combine")
| map("items2dict")'
  - '{{ test
| map("map","community.general.dict_kv","value")
| map("zip",[{"key":"name"},{"key":"address"}])
| map("map","flatten",1)
| map("map","combine")
| map("items2dict") }}'


On 8/29/24 7:38 AM, 'Rowe, Walter P. (Fed)' via Ansible Project wrote:
https://docs.ansible.com/ansible/latest/collections/community/general/dict_filter.html 



This is an even more elegant solution using the community.general.dict 
module:



- name: list2dict

  set_fact:

    list2dict: >-

      {{ test | map('zip', ['name', 'addr'])

            | map('map', 'reverse')

            | map('community.general.dict') }}


- name: list2dict

  debug: var=list2dict




Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Aug 29, 2024, at 7:22 AM, Rowe, Walter P. (Fed) 
 wrote:




- name: list of list to list of dict
  hosts: localhost
  become: false
  gather_facts: false
  vars:
    test:
      - - host1
        - fd99:::1
      - - host1
        - 10.0.1.1
      - - host2
        - fd99:::1
      - - host2
        - 10.0.1.1
      - - foo
        - fd99:::1
      - - foo
        - 10.0.1.1
      - - baz
        - fd99:::1
      - - baz
        - 10.0.1.1
  tasks:
    - name: test
      debug: var=test

    - name: list 2 dict
      set_fact:
        list2dict: "{{ list2dict|default([]) + [ thisdict ] }}"
      loop: "{{ test }}"
      vars:
        thisdict: { name: "{{ item.0 }}", addr: "{{ item.1 }}" }

    - name: list2dict
      debug: var=list2dict




Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123


On Aug 29, 2024, at 5:40 AM, Dick Visser  wrote:

Hii

I have something like this in my vars:

test:
  - - host1
    - fd99:::1
  - - host1
    - 10.0.1.1
  - - host2
    - fd99:::1
  - - host2
    - 10.0.1.1
  - - foo
    - fd99:::1
  - - foo
    - 10.0.1.1
  - - baz
    - fd99:::1
  - - baz
    - 10.0.1.1


Each first and second list item should become keys in a dict, like this:

conv:
  - name: host1
    address: fd99:::1
  - name: host1
    address: 10.0.1.1
  - name: host2
    address: fd99:::1
  - name: host2
    address: 10.0.1.1
  - name: foo
    address: fd99:::1
  - name: foo
    address: 10.0.1.1
  - name: baz
    address: fd99:::1
  - name: baz
    address: 10.0.1.1

I tried a few things with mapping and filtering, but can't see how 
to do it

any suggestions? Ideally no tasks, just filters

thx




--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAF8BbLamT%3Ds3H4R%3DcxShSg16KrSr%2B4%3D%3DUytgZbjPivhMK1rfmg%40mail.gmail.com 
.




--
You received this message because you are subscribed to the Google 
Groups "Ansible Project" 

Re: [ansible-project] list of lists, to list of dicts?

2024-08-29 Thread Dick Visser
On Thu, 29 Aug 2024 at 13:38, 'Rowe, Walter P. (Fed)' via Ansible
Project  wrote:
>
> https://docs.ansible.com/ansible/latest/collections/community/general/dict_filter.html
>
> This is an even more elegant solution using the community.general.dict module:
>
>
> - name: list2dict
>
>   set_fact:
>
> list2dict: >-
>
>   {{ test | map('zip', ['name', 'addr'])
>
> | map('map', 'reverse')
>
> | map('community.general.dict') }}


perfect, thx!!

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAF8BbLbt-LJ-ODEYQ%2BcFypRBOU%3DNxLZgzU4WhAAo_hn2_0Uh6w%40mail.gmail.com.


Re: [ansible-project] list of lists, to list of dicts?

2024-08-29 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
https://docs.ansible.com/ansible/latest/collections/community/general/dict_filter.html

This is an even more elegant solution using the community.general.dict module:



- name: list2dict

  set_fact:

list2dict: >-

  {{ test | map('zip', ['name', 'addr'])

| map('map', 'reverse')

| map('community.general.dict') }}


- name: list2dict

  debug: var=list2dict



Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Aug 29, 2024, at 7:22 AM, Rowe, Walter P. (Fed)  wrote:



- name: list of list to list of dict
  hosts: localhost
  become: false
  gather_facts: false
  vars:
test:
  - - host1
- fd99:::1
  - - host1
- 10.0.1.1
  - - host2
- fd99:::1
  - - host2
- 10.0.1.1
  - - foo
- fd99:::1
  - - foo
- 10.0.1.1
  - - baz
- fd99:::1
  - - baz
- 10.0.1.1
  tasks:
- name: test
  debug: var=test

- name: list 2 dict
  set_fact:
list2dict: "{{ list2dict|default([]) + [ thisdict ] }}"
  loop: "{{ test }}"
  vars:
thisdict: { name: "{{ item.0 }}", addr: "{{ item.1 }}" }

- name: list2dict
  debug: var=list2dict




Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Aug 29, 2024, at 5:40 AM, Dick Visser  wrote:

Hii

I have something like this in my vars:

test:
  - - host1
- fd99:::1
  - - host1
- 10.0.1.1
  - - host2
- fd99:::1
  - - host2
- 10.0.1.1
  - - foo
- fd99:::1
  - - foo
- 10.0.1.1
  - - baz
- fd99:::1
  - - baz
- 10.0.1.1


Each first and second list item should become keys in a dict, like this:

conv:
  - name: host1
address: fd99:::1
  - name: host1
address: 10.0.1.1
  - name: host2
address: fd99:::1
  - name: host2
address: 10.0.1.1
  - name: foo
address: fd99:::1
  - name: foo
address: 10.0.1.1
  - name: baz
address: fd99:::1
  - name: baz
address: 10.0.1.1

I tried a few things with mapping and filtering, but can't see how to do it
any suggestions? Ideally no tasks, just filters

thx




--
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 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAF8BbLamT%3Ds3H4R%3DcxShSg16KrSr%2B4%3D%3DUytgZbjPivhMK1rfmg%40mail.gmail.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6F5FBEE5-028A-4AB2-ADC9-5B2B535290F7%40nist.gov.


Re: [ansible-project] list of lists, to list of dicts?

2024-08-29 Thread 'Rowe, Walter P. (Fed)' via Ansible Project


- name: list of list to list of dict

  hosts: localhost

  become: false

  gather_facts: false

  vars:

test:

  - - host1

- fd99:::1

  - - host1

- 10.0.1.1

  - - host2

- fd99:::1

  - - host2

- 10.0.1.1

  - - foo

- fd99:::1

  - - foo

- 10.0.1.1

  - - baz

- fd99:::1

  - - baz

- 10.0.1.1

  tasks:

- name: test

  debug: var=test


- name: list 2 dict

  set_fact:

list2dict: "{{ list2dict|default([]) + [ thisdict ] }}"

  loop: "{{ test }}"

  vars:

thisdict: { name: "{{ item.0 }}", addr: "{{ item.1 }}" }


- name: list2dict

  debug: var=list2dict




Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Aug 29, 2024, at 5:40 AM, Dick Visser  wrote:

Hii

I have something like this in my vars:

test:
  - - host1
- fd99:::1
  - - host1
- 10.0.1.1
  - - host2
- fd99:::1
  - - host2
- 10.0.1.1
  - - foo
- fd99:::1
  - - foo
- 10.0.1.1
  - - baz
- fd99:::1
  - - baz
- 10.0.1.1


Each first and second list item should become keys in a dict, like this:

conv:
  - name: host1
address: fd99:::1
  - name: host1
address: 10.0.1.1
  - name: host2
address: fd99:::1
  - name: host2
address: 10.0.1.1
  - name: foo
address: fd99:::1
  - name: foo
address: 10.0.1.1
  - name: baz
address: fd99:::1
  - name: baz
address: 10.0.1.1

I tried a few things with mapping and filtering, but can't see how to do it
any suggestions? Ideally no tasks, just filters

thx




--
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 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAF8BbLamT%3Ds3H4R%3DcxShSg16KrSr%2B4%3D%3DUytgZbjPivhMK1rfmg%40mail.gmail.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/8DA3C6CD-942A-4462-B67C-7B07E0ADFD6C%40nist.gov.


Re: [ansible-project] Need a help on manage various OS

2024-08-28 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
https://docs.ansible.com/ansible/latest/os_guide/windows_winrm.html

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Aug 28, 2024, at 9:06 AM, 'Rowe, Walter P. (Fed)' via Ansible Project 
 wrote:

You can set the variables to define login details in the group definition.

https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html#inheriting-variable-values-group-variables-for-groups-of-groups

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Aug 28, 2024, at 8:33 AM, Thirumalai Raja A  
wrote:

I can create a group in inventory but how can I use credentials for that? You 
ask me to have two different playbooks.
if its single playbook how can i mention credentials for windows and linux 
separately

On Wed, 28 Aug 2024 at 17:52, 'Rowe, Walter P. (Fed)' via Ansible Project 
mailto:[email protected]>> 
wrote:
I would split your inventory into groups by platform since Windows login 
requires a different method. For the Windows group you can configure the login 
method for Windows as needed to use RDP.

You could have two plays in the playbook that target the different groups in 
the "hosts" tag.

- name: reboot windows hosts
  hosts: windows_hosts
  tasks:
... do the reboots via winrm

- name: reboot linux hosts
  hosts: linux_hosts
  tasks:
... do the reboots via SSH

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Aug 28, 2024, at 7:56 AM, Thirumalai Raja A 
mailto:[email protected]>> wrote:

hi all,

We are using AWX to perform ansible jobs. I need help because I wanted to apply 
a restart schedule for a set of linux and windows vms. for linux we have a 
local account with ssh key and for windows we have a service account of AD.

So how can I run my single job handling windows and linux hosts in single 
playbook?
(i can only add once machine credential in a AWX template).


Regards,
Thirumalai.

--
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 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CALyK%3Dg-VzGVBv_9bYzAVDhuh08QKGuPNzY4CGriBAW6LatBe4g%40mail.gmail.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 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3A46C80F-BC0D-4FB4-94DD-4EB4F21CCD45%40nist.gov.

--
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 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CALyK%3Dg-g1obXmH38QY3RVcTnOav3cFFFHrDZH7XLCTjVDopvRA%40mail.gmail.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 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2959DB1A-8F2D-47C8-B447-AB2A4019E6FB%40nist.gov.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/DE524A41-9D6C-4585-BFAB-5C45661FE331%40nist.gov.


Re: [ansible-project] Need a help on manage various OS

2024-08-28 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
You can set the variables to define login details in the group definition.

https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html#inheriting-variable-values-group-variables-for-groups-of-groups

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Aug 28, 2024, at 8:33 AM, Thirumalai Raja A  
wrote:

I can create a group in inventory but how can I use credentials for that? You 
ask me to have two different playbooks.
if its single playbook how can i mention credentials for windows and linux 
separately

On Wed, 28 Aug 2024 at 17:52, 'Rowe, Walter P. (Fed)' via Ansible Project 
mailto:[email protected]>> 
wrote:
I would split your inventory into groups by platform since Windows login 
requires a different method. For the Windows group you can configure the login 
method for Windows as needed to use RDP.

You could have two plays in the playbook that target the different groups in 
the "hosts" tag.

- name: reboot windows hosts
  hosts: windows_hosts
  tasks:
... do the reboots via winrm

- name: reboot linux hosts
  hosts: linux_hosts
  tasks:
... do the reboots via SSH

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Aug 28, 2024, at 7:56 AM, Thirumalai Raja A 
mailto:[email protected]>> wrote:

hi all,

We are using AWX to perform ansible jobs. I need help because I wanted to apply 
a restart schedule for a set of linux and windows vms. for linux we have a 
local account with ssh key and for windows we have a service account of AD.

So how can I run my single job handling windows and linux hosts in single 
playbook?
(i can only add once machine credential in a AWX template).


Regards,
Thirumalai.

--
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 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CALyK%3Dg-VzGVBv_9bYzAVDhuh08QKGuPNzY4CGriBAW6LatBe4g%40mail.gmail.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 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3A46C80F-BC0D-4FB4-94DD-4EB4F21CCD45%40nist.gov.

--
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 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CALyK%3Dg-g1obXmH38QY3RVcTnOav3cFFFHrDZH7XLCTjVDopvRA%40mail.gmail.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2959DB1A-8F2D-47C8-B447-AB2A4019E6FB%40nist.gov.


Re: [ansible-project] Need a help on manage various OS

2024-08-28 Thread Thirumalai Raja A
I can create a group in inventory but how can I use credentials for that?
You ask me to have two different playbooks.
if its single playbook how can i mention credentials for windows and linux
separately

On Wed, 28 Aug 2024 at 17:52, 'Rowe, Walter P. (Fed)' via Ansible Project <
[email protected]> wrote:

> I would split your inventory into groups by platform since Windows login
> requires a different method. For the Windows group you can configure the
> login method for Windows as needed to use RDP.
>
> You could have two plays in the playbook that target the different groups
> in the "hosts" tag.
>
> - name: reboot windows hosts
>   hosts: windows_hosts
>   tasks:
> ... do the reboots via winrm
>
> - name: reboot linux hosts
>   hosts: linux_hosts
>   tasks:
> ... do the reboots via SSH
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services Division
> Mobile: 202.355.4123
>
> On Aug 28, 2024, at 7:56 AM, Thirumalai Raja A 
> wrote:
>
> hi all,
>
> We are using AWX to perform ansible jobs. I need help because I wanted to
> apply a restart schedule for a set of linux and windows vms. for linux we
> have a local account with ssh key and for windows we have a service account
> of AD.
>
> So how can I run my single job handling windows and linux hosts in
> single playbook?
> (i can only add once machine credential in a AWX template).
>
>
> Regards,
> Thirumalai.
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CALyK%3Dg-VzGVBv_9bYzAVDhuh08QKGuPNzY4CGriBAW6LatBe4g%40mail.gmail.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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/3A46C80F-BC0D-4FB4-94DD-4EB4F21CCD45%40nist.gov
> 
> .
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CALyK%3Dg-g1obXmH38QY3RVcTnOav3cFFFHrDZH7XLCTjVDopvRA%40mail.gmail.com.


Re: [ansible-project] Need a help on manage various OS

2024-08-28 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
I would split your inventory into groups by platform since Windows login 
requires a different method. For the Windows group you can configure the login 
method for Windows as needed to use RDP.

You could have two plays in the playbook that target the different groups in 
the "hosts" tag.

- name: reboot windows hosts
  hosts: windows_hosts
  tasks:
... do the reboots via winrm

- name: reboot linux hosts
  hosts: linux_hosts
  tasks:
... do the reboots via SSH

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Aug 28, 2024, at 7:56 AM, Thirumalai Raja A  
wrote:

hi all,

We are using AWX to perform ansible jobs. I need help because I wanted to apply 
a restart schedule for a set of linux and windows vms. for linux we have a 
local account with ssh key and for windows we have a service account of AD.

So how can I run my single job handling windows and linux hosts in single 
playbook?
(i can only add once machine credential in a AWX template).


Regards,
Thirumalai.

--
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 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CALyK%3Dg-VzGVBv_9bYzAVDhuh08QKGuPNzY4CGriBAW6LatBe4g%40mail.gmail.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3A46C80F-BC0D-4FB4-94DD-4EB4F21CCD45%40nist.gov.


Re: [ansible-project] Re: Dealing with list content

2024-08-21 Thread Alex Wanderley
Thanks, Vladimir!

That worked really well.
It generated the file much faster than the lineinfile alternative.

Thank you as well for the templating doc/link.
After I figure out what info my "client" wants to extract from VMware,
building a report will be the next step and so far I'm planning to use
templates for that.

Alex

On Tue, Aug 20, 2024 at 4:57 PM Vladimir Botka  wrote:

> On Tue, 20 Aug 2024 16:16:17 -0600
> Alex Wanderley  wrote:
>
> > Hi,
> >
> > OK, answering my own question, I was able to send the parsed vm_list
> > content to a file using this task:
> >
> >  - name: Copy list to file
> >ansible.builtin.lineinfile:
> >   dest: 
> >   line: "{{ item['guest_name'] }}"
> >   state: present
> >   create: yes
> >loop: "{{ vm_list.virtual_machines }}"
> >
> > There would be a different/better way of accomplishing that...?
>
> Try this
>
>   - copy:
>   dest: 
>   content: |
> {% for i in vm_list.virtual_machines %}
> {{ i.guest_name }}
> {% endfor %}
>
> See
>
> https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_templating.html
>
> --
> Vladimir Botka
>


-- 



[image: Edmonton_sig_RGB_S.jpg]

Alex Wanderley

Application and Infrastructure Analyst II
Server Solutions & Automation

Financial and Corporate Services | Open City and Technology



780-496-4156  Office

780-819-0273  Mobile



City of Edmonton

Century Place, 19th Floor

9803 102A Avenue NW

Edmonton AB, T5J 3A3



All information contained in this email post is proprietary to the City of
Edmonton, confidential and intended only for the addressed recipient. If
you have received this post in error, please disregard the contents, inform
the sender of the misdirection, and remove it from your system. The
copying, dissemination or distribution of this email, if misdirected, is
strictly prohibited.

-- 
*The contents of this message and any attachment(s) are confidential, 
proprietary to the City of Edmonton, and are intended only for the 
addressed recipient. If you have received this in error, please disregard 
the contents, inform the sender of the misdirection, and remove it from 
your system. The copying, dissemination, or distribution of this message, 
if misdirected, is strictly prohibited.*

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CADp8UUTUn_JQKS8PtnNg3z2dR3cjzi1Td6pRsTFnqUZDiFc-SA%40mail.gmail.com.


Re: [ansible-project] Dealing with list content

2024-08-21 Thread Alex Wanderley
Thanks, Nitesh...!
I now have a much cleaner printout!

Alex

On Wed, Aug 21, 2024 at 1:56 AM Nitesh Dudhe 
wrote:

> Dear Alex,
>
> For your output minimisation:
> you can arrange your task like this:
>
> - name: Collect list of VMs in cluster
>   community.vmware.vmware_vm_info:
>  validate_certs: false
>   register: vm_list
>
> - name: Print list
>   ansible.builtin.debug:
>  msg: "{{ item['guest_name'] }}"
>   loop: "{{ vm_list.virtual_machines }}"
> loop_control:
>  label:  "Collected vm-name"  # either you put empty string or some
> relevant string
>
>
>
> output will be like this:
>
> ok: [localhost] => (item=Collected vm-name)
> msg": "server01"
> ok: [localhost] => (item=Collected vm-name)
> msg": "server02"
> ok: [localhost] => (item=Collected vm-name)
> msg": "server03"
>
> no more unwanted text during the debug for each iteration:
> eg.  (item={'guest_name': 'xx', 'guest_fullname': 'Microsoft Windows
> Server 2022 (64-bit)', 'power_state': 'poweredOn', 'ip_address': 'xx',
> 'mac_address': ['xx'], 'uuid': 'xx', 'instance_uuid': 'xx',
> 'vm_network': {'xx': {'ipv4': ['xx'], 'ipv6': []}},
> 'esxi_hostname': 'xx', 'datacenter': 'xx', 'cluster': 'xx',
> 'resource_pool': None, 'attributes': {}, 'tags': [], 'folder': 'xx',
> 'moid': 'xx', 'datastore_url': [{'name': 'xx', 'url': 'xx'}],
> 'allocated': {}}) =>
>
> I hope this helps
>
>
> Regards
> Nitesh Dudhe
>
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAGPd1LmKTJvoB5b3sWauUa6KBFpUKPVUTbPLkqBsC2KKdoYhGw%40mail.gmail.com
> 
> .
>


-- 



[image: Edmonton_sig_RGB_S.jpg]

Alex Wanderley

Application and Infrastructure Analyst II
Server Solutions & Automation

Financial and Corporate Services | Open City and Technology



780-496-4156  Office

780-819-0273  Mobile



City of Edmonton

Century Place, 19th Floor

9803 102A Avenue NW

Edmonton AB, T5J 3A3



All information contained in this email post is proprietary to the City of
Edmonton, confidential and intended only for the addressed recipient. If
you have received this post in error, please disregard the contents, inform
the sender of the misdirection, and remove it from your system. The
copying, dissemination or distribution of this email, if misdirected, is
strictly prohibited.

-- 
*The contents of this message and any attachment(s) are confidential, 
proprietary to the City of Edmonton, and are intended only for the 
addressed recipient. If you have received this in error, please disregard 
the contents, inform the sender of the misdirection, and remove it from 
your system. The copying, dissemination, or distribution of this message, 
if misdirected, is strictly prohibited.*

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CADp8UUS374t6n3-Bjs37RCUHU4CzaPkDdQDgEVNgXi2Q79ke%2BA%40mail.gmail.com.


Re: [ansible-project] Unable to execute shell script

2024-08-21 Thread Yogita Patil
Ah ok thanks for letting me know, will fix that.

On Wed, Aug 21, 2024 at 5:13 PM Todd Lewis  wrote:

> The "stat" failed because you have a "." in front of
> "/usr/src/power_consumption.sh".
>
> On 8/21/24 8:57 AM, Yogita Patil wrote:
>
> Ok thanks Todd.
>
> Also now I am getting a different error, after I cleaned up the yml to
> keep only 1 task -
>
>  FAILED! => {
> "ansible_facts": {
> "discovered_interpreter_python": "/usr/bin/python3"
> },
> "changed": true,
> "cmd": [
> "stat",
> "./usr/src/power_consumption.sh"
> ],
> "delta": "0:00:00.002128",
> "end": "2024-08-21 16:53:50.376199",
> "invocation": {
> "module_args": {
> "_raw_params": "stat ./usr/src/power_consumption.sh",
> "_uses_shell": false,
> "argv": null,
> "chdir": null,
> "creates": null,
> "executable": null,
> "removes": null,
> "stdin": null,
> "stdin_add_newline": true,
> "strip_empty_ends": true
> }
> },
> "msg": "non-zero return code",
> "rc": 1,
> "start": "2024-08-21 16:53:50.374071",
> "stderr": "stat: cannot statx './usr/src/power_consumption.sh': No
> such file or directory",
> "stderr_lines": [
> "stat: cannot statx './usr/src/power_consumption.sh': No such file
> or directory"
> ],
> "stdout": "",
> "stdout_lines": []
> }
>
>
> Content of my yml are -
>
> - name: Shell script test
>   hosts: all
>   gather_facts: false
>   tasks:
>
>
>  - name: Run a script in another way
>ansible.builtin.command: stat ./usr/src/power_consumption.sh
>ignore_errors: true
>
> File does exist in the folder /usr/src on the controller node and the
> ansible host on which I am trying to execute the script both -
>
> [image: image.png]
>
>
> Contents of yml are -
>
>
> On Wed, Aug 21, 2024 at 4:46 PM Todd Lewis  wrote:
>
>> Yogita,
>>
>> Do us a favor please and change this:
>>
>> ansible.builtin.command: ./power_consumption.sh
>>
>> to this:
>>
>> ansible.builtin.command: stat ./power_consumption.sh
>>
>> and let us see the results. Thanks.
>> —
>> Todd
>>
>> On 8/21/24 8:12 AM, Yogita Patil wrote:
>>
>> Yes yes I understand what you mean, and it does work if I add
>> #!/bin/bash’  at the beginning of my foo.sh
>>
>> contents of foo.sh -
>> #!/bin/bash
>> echo "Hello world"
>>
>> However my power consumption script fails. Any idea what I am doing wrong
>> there?
>>
>> Many thanks for your help!
>>
>> -Yogita.
>>
>> On Wed, Aug 21, 2024 at 4:07 PM Stephen Maher  wrote:
>>
>>> Hi,
>>>
>>> Your bash script must in include ‘#!/bin/bash’ to allow for its
>>> execution using bash hence the suggestion to add the executable verb to
>>> prove this was the case.
>>>
>>> Regards
>>>
>>>
>>>
>>> On 21 Aug 2024, at 11:25, Yogita Patil  wrote:
>>>
>>> The bash was just a trial, the is the script that I really care about
>>> running which runs perfectly from the command line -
>>> myScript.yml
>>>
>>> - name: Shell script test
>>>   hosts: all
>>>   tasks:
>>>
>>>  - name: Run a shell command
>>>ansible.builtin.shell: power_consumption.sh
>>>register: foo_result
>>>args:
>>>  chdir: /usr/src
>>>ignore_errors: true
>>>
>>>  - name: Run a script
>>>ansible.builtin.script:
>>>  cmd: /usr/src/power_consumption.sh
>>>ignore_errors: true
>>>
>>>  - name: Run a script in another way
>>>ansible.builtin.script: /usr/src/power_consumption.sh
>>>ignore_errors: true
>>>
>>>  - name: Run a script via command line
>>>ansible.builtin.command: ./power_consumption.sh
>>>args:
>>>  chdir: /usr/src
>>>ignore_errors: true
>>>
>>>
>>> # - name: Run a script second way
>>> #   ansible.builtin.script:
>>> #   cmd: /usr/src/power_consumption.sh
>>>
>>>  - name: Run a shell command using output of the previous task
>>>ansible.builtin.shell: /usr/src/bar.sh
>>>when: foo_result.rc == 5
>>>
>>>
>>> The contents of the power_consumption.sh script are -
>>>
>>> hostfqdn=$(hostname --fqdn)
>>> time=1
>>> declare T0=($(cat /sys/class/powercap/intel-rapl/*/energy_uj)); sleep
>>> $time; declare T1=($(cat /sys/class/powercap/intel-rapl/*/energy_uj))
>>> for i in "${!T0[@]}"; do echo - | awk "{printf \"%.1f W\",
>>> $((${T1[i]}-${T0[i]})) / $time / 1e6 }" >> $hostfqdn.txt ; done
>>>
>>>
>>> I have no idea what I am doing wrong, I have tried to put the script in
>>> /usr/bin as well but same result for all tasks -
>>>
>>> TASK [Run a script via command line] *
>>> The full traceback is:
>>>   File
>>> "/tmp/ansible_ansible.legacy.command_payload_p_z2bc7h/ansible_ansible.legacy.command_payload.zip/ansible/module_utils/basic.py",
>>> line 2050, in run_command
>>> cmd = subprocess.Popen(args, **kwargs)
>>>   
>>>   File 

Re: [ansible-project] Unable to execute shell script

2024-08-21 Thread Todd Lewis
The "stat" failed because you have a "." in front of 
"/usr/src/power_consumption.sh".


On 8/21/24 8:57 AM, Yogita Patil wrote:

Ok thanks Todd.

Also now I am getting a different error, after I cleaned up the yml to 
keep only 1 task -


 FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": true,
    "cmd": [
        "stat",
        "./usr/src/power_consumption.sh"
    ],
    "delta": "0:00:00.002128",
    "end": "2024-08-21 16:53:50.376199",
    "invocation": {
        "module_args": {
            "_raw_params": "stat ./usr/src/power_consumption.sh",
            "_uses_shell": false,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true
        }
    },
    "msg": "non-zero return code",
    "rc": 1,
    "start": "2024-08-21 16:53:50.374071",
    "stderr": "stat: cannot statx './usr/src/power_consumption.sh': No 
such file or directory",

    "stderr_lines": [
        "stat: cannot statx './usr/src/power_consumption.sh': No such 
file or directory"

    ],
    "stdout": "",
    "stdout_lines": []
}


Content of my yml are -

- name: Shell script test
  hosts: all
  gather_facts: false
  tasks:


     - name: Run a script in another way
       ansible.builtin.command: stat ./usr/src/power_consumption.sh
       ignore_errors: true

File does exist in the folder /usr/src on the controller node and the 
ansible host on which I am trying to execute the script both -


image.png


Contents of yml are -


On Wed, Aug 21, 2024 at 4:46 PM Todd Lewis  wrote:

Yogita,

Do us a favor please and change this:

ansible.builtin.command: ./power_consumption.sh

to this:

ansible.builtin.command: stat ./power_consumption.sh

and let us see the results. Thanks.
—
Todd

On 8/21/24 8:12 AM, Yogita Patil wrote:

Yes yes I understand what you mean, and it does work if I add 
#!/bin/bash’  at the beginning of my foo.sh

contents of foo.sh -
#!/bin/bash
echo "Hello world"

However my power consumption script fails. Any idea what I
am doing wrong there?

Many thanks for your help!

-Yogita.

On Wed, Aug 21, 2024 at 4:07 PM Stephen Maher
 wrote:

Hi,

Your bash script must in include ‘#!/bin/bash’ to allow for
its execution using bash hence the suggestion to add the
executable verb to prove this was the case.

Regards




On 21 Aug 2024, at 11:25, Yogita Patil
 wrote:

The bash was just a trial, the is the script that I really
care about running which runs perfectly from the command line -
myScript.yml

- name: Shell script test
  hosts: all
  tasks:

     - name: Run a shell command
       ansible.builtin.shell: power_consumption.sh
       register: foo_result
       args:
         chdir: /usr/src
       ignore_errors: true

     - name: Run a script
       ansible.builtin.script:
         cmd: /usr/src/power_consumption.sh
       ignore_errors: true

     - name: Run a script in another way
       ansible.builtin.script: /usr/src/power_consumption.sh
       ignore_errors: true

     - name: Run a script via command line
       ansible.builtin.command: ./power_consumption.sh
       args:
         chdir: /usr/src
       ignore_errors: true


#     - name: Run a script second way
#       ansible.builtin.script:
#       cmd: /usr/src/power_consumption.sh

     - name: Run a shell command using output of the
previous task
       ansible.builtin.shell: /usr/src/bar.sh
       when: foo_result.rc == 5


The contents of the power_consumption.sh script are -

hostfqdn=$(hostname --fqdn)
time=1
declare T0=($(cat
/sys/class/powercap/intel-rapl/*/energy_uj)); sleep $time;
declare T1=($(cat /sys/class/powercap/intel-rapl/*/energy_uj))
for i in "${!T0[@]}"; do echo - | awk "{printf \"%.1f W\",
$((${T1[i]}-${T0[i]})) / $time / 1e6 }" >> $hostfqdn.txt ; done


I have no idea what I am doing wrong, I have tried to put
the script in /usr/bin as well but same result for all tasks -

TASK [Run a script via command line] *
The full traceback is:
  File

"/tmp/ansible_ansible.legacy.command_payload_p_z2bc7h/ansible_ansible.legacy.command_payload.zip/ansible/module_utils/basic.py",
line 2050, in run_command
    cmd = subprocess.Popen(args, **kwargs)

  File "/usr/lib/python3.11/subprocess.py", line 1024, in
__init__
    

Re: [ansible-project] Unable to execute shell script

2024-08-21 Thread Yogita Patil
This worked for me ...hooray!!!  Many thanks everyone for all your inputs
and support!!!

- name: Shell script test
  hosts: all
  gather_facts: false
  tasks:

  - name: Start application
shell: "/usr/src/power_consumption.sh"
args:
  chdir: "/usr/src"
  executable: "/bin/bash"

On Wed, Aug 21, 2024 at 4:57 PM Yogita Patil 
wrote:

> Ok thanks Todd.
>
> Also now I am getting a different error, after I cleaned up the yml to
> keep only 1 task -
>
>  FAILED! => {
> "ansible_facts": {
> "discovered_interpreter_python": "/usr/bin/python3"
> },
> "changed": true,
> "cmd": [
> "stat",
> "./usr/src/power_consumption.sh"
> ],
> "delta": "0:00:00.002128",
> "end": "2024-08-21 16:53:50.376199",
> "invocation": {
> "module_args": {
> "_raw_params": "stat ./usr/src/power_consumption.sh",
> "_uses_shell": false,
> "argv": null,
> "chdir": null,
> "creates": null,
> "executable": null,
> "removes": null,
> "stdin": null,
> "stdin_add_newline": true,
> "strip_empty_ends": true
> }
> },
> "msg": "non-zero return code",
> "rc": 1,
> "start": "2024-08-21 16:53:50.374071",
> "stderr": "stat: cannot statx './usr/src/power_consumption.sh': No
> such file or directory",
> "stderr_lines": [
> "stat: cannot statx './usr/src/power_consumption.sh': No such file
> or directory"
> ],
> "stdout": "",
> "stdout_lines": []
> }
>
>
> Content of my yml are -
>
> - name: Shell script test
>   hosts: all
>   gather_facts: false
>   tasks:
>
>
>  - name: Run a script in another way
>ansible.builtin.command: stat ./usr/src/power_consumption.sh
>ignore_errors: true
>
> File does exist in the folder /usr/src on the controller node and the
> ansible host on which I am trying to execute the script both -
>
> [image: image.png]
>
>
> Contents of yml are -
>
>
> On Wed, Aug 21, 2024 at 4:46 PM Todd Lewis  wrote:
>
>> Yogita,
>>
>> Do us a favor please and change this:
>>
>> ansible.builtin.command: ./power_consumption.sh
>>
>> to this:
>>
>> ansible.builtin.command: stat ./power_consumption.sh
>>
>> and let us see the results. Thanks.
>> —
>> Todd
>>
>> On 8/21/24 8:12 AM, Yogita Patil wrote:
>>
>> Yes yes I understand what you mean, and it does work if I add
>> #!/bin/bash’  at the beginning of my foo.sh
>>
>> contents of foo.sh -
>> #!/bin/bash
>> echo "Hello world"
>>
>> However my power consumption script fails. Any idea what I am doing wrong
>> there?
>>
>> Many thanks for your help!
>>
>> -Yogita.
>>
>> On Wed, Aug 21, 2024 at 4:07 PM Stephen Maher  wrote:
>>
>>> Hi,
>>>
>>> Your bash script must in include ‘#!/bin/bash’ to allow for its
>>> execution using bash hence the suggestion to add the executable verb to
>>> prove this was the case.
>>>
>>> Regards
>>>
>>>
>>>
>>> On 21 Aug 2024, at 11:25, Yogita Patil  wrote:
>>>
>>> The bash was just a trial, the is the script that I really care about
>>> running which runs perfectly from the command line -
>>> myScript.yml
>>>
>>> - name: Shell script test
>>>   hosts: all
>>>   tasks:
>>>
>>>  - name: Run a shell command
>>>ansible.builtin.shell: power_consumption.sh
>>>register: foo_result
>>>args:
>>>  chdir: /usr/src
>>>ignore_errors: true
>>>
>>>  - name: Run a script
>>>ansible.builtin.script:
>>>  cmd: /usr/src/power_consumption.sh
>>>ignore_errors: true
>>>
>>>  - name: Run a script in another way
>>>ansible.builtin.script: /usr/src/power_consumption.sh
>>>ignore_errors: true
>>>
>>>  - name: Run a script via command line
>>>ansible.builtin.command: ./power_consumption.sh
>>>args:
>>>  chdir: /usr/src
>>>ignore_errors: true
>>>
>>>
>>> # - name: Run a script second way
>>> #   ansible.builtin.script:
>>> #   cmd: /usr/src/power_consumption.sh
>>>
>>>  - name: Run a shell command using output of the previous task
>>>ansible.builtin.shell: /usr/src/bar.sh
>>>when: foo_result.rc == 5
>>>
>>>
>>> The contents of the power_consumption.sh script are -
>>>
>>> hostfqdn=$(hostname --fqdn)
>>> time=1
>>> declare T0=($(cat /sys/class/powercap/intel-rapl/*/energy_uj)); sleep
>>> $time; declare T1=($(cat /sys/class/powercap/intel-rapl/*/energy_uj))
>>> for i in "${!T0[@]}"; do echo - | awk "{printf \"%.1f W\",
>>> $((${T1[i]}-${T0[i]})) / $time / 1e6 }" >> $hostfqdn.txt ; done
>>>
>>>
>>> I have no idea what I am doing wrong, I have tried to put the script in
>>> /usr/bin as well but same result for all tasks -
>>>
>>> TASK [Run a script via command line] *
>>> The full traceback is:
>>>   File
>>> "/tmp/ansible_ansible.legacy.command_payload_p_z2bc7h/ansible_ansible.legacy.command_payload.zip/ansible/module_utils/basic.py",
>>> line 2050, in run_command
>>> cmd = 

Re: [ansible-project] Unable to execute shell script

2024-08-21 Thread Yogita Patil
Ok thanks Todd.

Also now I am getting a different error, after I cleaned up the yml to keep
only 1 task -

 FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": true,
"cmd": [
"stat",
"./usr/src/power_consumption.sh"
],
"delta": "0:00:00.002128",
"end": "2024-08-21 16:53:50.376199",
"invocation": {
"module_args": {
"_raw_params": "stat ./usr/src/power_consumption.sh",
"_uses_shell": false,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true
}
},
"msg": "non-zero return code",
"rc": 1,
"start": "2024-08-21 16:53:50.374071",
"stderr": "stat: cannot statx './usr/src/power_consumption.sh': No such
file or directory",
"stderr_lines": [
"stat: cannot statx './usr/src/power_consumption.sh': No such file
or directory"
],
"stdout": "",
"stdout_lines": []
}


Content of my yml are -

- name: Shell script test
  hosts: all
  gather_facts: false
  tasks:


 - name: Run a script in another way
   ansible.builtin.command: stat ./usr/src/power_consumption.sh
   ignore_errors: true

File does exist in the folder /usr/src on the controller node and the
ansible host on which I am trying to execute the script both -

[image: image.png]


Contents of yml are -


On Wed, Aug 21, 2024 at 4:46 PM Todd Lewis  wrote:

> Yogita,
>
> Do us a favor please and change this:
>
> ansible.builtin.command: ./power_consumption.sh
>
> to this:
>
> ansible.builtin.command: stat ./power_consumption.sh
>
> and let us see the results. Thanks.
> —
> Todd
>
> On 8/21/24 8:12 AM, Yogita Patil wrote:
>
> Yes yes I understand what you mean, and it does work if I add
> #!/bin/bash’  at the beginning of my foo.sh
>
> contents of foo.sh -
> #!/bin/bash
> echo "Hello world"
>
> However my power consumption script fails. Any idea what I am doing wrong
> there?
>
> Many thanks for your help!
>
> -Yogita.
>
> On Wed, Aug 21, 2024 at 4:07 PM Stephen Maher  wrote:
>
>> Hi,
>>
>> Your bash script must in include ‘#!/bin/bash’ to allow for its execution
>> using bash hence the suggestion to add the executable verb to prove this
>> was the case.
>>
>> Regards
>>
>>
>>
>> On 21 Aug 2024, at 11:25, Yogita Patil  wrote:
>>
>> The bash was just a trial, the is the script that I really care about
>> running which runs perfectly from the command line -
>> myScript.yml
>>
>> - name: Shell script test
>>   hosts: all
>>   tasks:
>>
>>  - name: Run a shell command
>>ansible.builtin.shell: power_consumption.sh
>>register: foo_result
>>args:
>>  chdir: /usr/src
>>ignore_errors: true
>>
>>  - name: Run a script
>>ansible.builtin.script:
>>  cmd: /usr/src/power_consumption.sh
>>ignore_errors: true
>>
>>  - name: Run a script in another way
>>ansible.builtin.script: /usr/src/power_consumption.sh
>>ignore_errors: true
>>
>>  - name: Run a script via command line
>>ansible.builtin.command: ./power_consumption.sh
>>args:
>>  chdir: /usr/src
>>ignore_errors: true
>>
>>
>> # - name: Run a script second way
>> #   ansible.builtin.script:
>> #   cmd: /usr/src/power_consumption.sh
>>
>>  - name: Run a shell command using output of the previous task
>>ansible.builtin.shell: /usr/src/bar.sh
>>when: foo_result.rc == 5
>>
>>
>> The contents of the power_consumption.sh script are -
>>
>> hostfqdn=$(hostname --fqdn)
>> time=1
>> declare T0=($(cat /sys/class/powercap/intel-rapl/*/energy_uj)); sleep
>> $time; declare T1=($(cat /sys/class/powercap/intel-rapl/*/energy_uj))
>> for i in "${!T0[@]}"; do echo - | awk "{printf \"%.1f W\",
>> $((${T1[i]}-${T0[i]})) / $time / 1e6 }" >> $hostfqdn.txt ; done
>>
>>
>> I have no idea what I am doing wrong, I have tried to put the script in
>> /usr/bin as well but same result for all tasks -
>>
>> TASK [Run a script via command line] *
>> The full traceback is:
>>   File
>> "/tmp/ansible_ansible.legacy.command_payload_p_z2bc7h/ansible_ansible.legacy.command_payload.zip/ansible/module_utils/basic.py",
>> line 2050, in run_command
>> cmd = subprocess.Popen(args, **kwargs)
>>   
>>   File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__
>> self._execute_child(args, executable, preexec_fn, close_fds,
>>   File "/usr/lib/python3.11/subprocess.py", line 1901, in _execute_child
>> raise child_exception_type(errno_num, err_msg, err_filename)
>> fatal: [100.91.187.42]: FAILED! => {
>> "changed": false,
>> "cmd": "./power_consumption.sh",
>> "invocation": {
>> "module_args": {
>> "_raw_params": "./power_consumption.sh",
>>

Re: [ansible-project] Unable to execute shell script

2024-08-21 Thread Todd Lewis

Yogita,

Do us a favor please and change this:

   ansible.builtin.command: ./power_consumption.sh

to this:

   ansible.builtin.command: stat ./power_consumption.sh

and let us see the results. Thanks.
—
Todd

On 8/21/24 8:12 AM, Yogita Patil wrote:
Yes yes I understand what you mean, and it does work if I add 
#!/bin/bash’  at the beginning of my foo.sh


contents of foo.sh -
#!/bin/bash
echo "Hello world"

However my power consumption script fails. Any idea what I am doing 
wrong there?


Many thanks for your help!

-Yogita.

On Wed, Aug 21, 2024 at 4:07 PM Stephen Maher  wrote:

Hi,

Your bash script must in include ‘#!/bin/bash’ to allow for its
execution using bash hence the suggestion to add the executable
verb to prove this was the case.

Regards




On 21 Aug 2024, at 11:25, Yogita Patil 
wrote:

The bash was just a trial, the is the script that I really care
about running which runs perfectly from the command line -
myScript.yml

- name: Shell script test
  hosts: all
  tasks:

     - name: Run a shell command
       ansible.builtin.shell: power_consumption.sh
       register: foo_result
       args:
         chdir: /usr/src
       ignore_errors: true

     - name: Run a script
       ansible.builtin.script:
         cmd: /usr/src/power_consumption.sh
       ignore_errors: true

     - name: Run a script in another way
       ansible.builtin.script: /usr/src/power_consumption.sh
       ignore_errors: true

     - name: Run a script via command line
       ansible.builtin.command: ./power_consumption.sh
       args:
         chdir: /usr/src
       ignore_errors: true


#     - name: Run a script second way
#       ansible.builtin.script:
#       cmd: /usr/src/power_consumption.sh

     - name: Run a shell command using output of the previous task
       ansible.builtin.shell: /usr/src/bar.sh
       when: foo_result.rc == 5


The contents of the power_consumption.sh script are -

hostfqdn=$(hostname --fqdn)
time=1
declare T0=($(cat /sys/class/powercap/intel-rapl/*/energy_uj));
sleep $time; declare T1=($(cat
/sys/class/powercap/intel-rapl/*/energy_uj))
for i in "${!T0[@]}"; do echo - | awk "{printf \"%.1f W\",
$((${T1[i]}-${T0[i]})) / $time / 1e6 }" >> $hostfqdn.txt ; done


I have no idea what I am doing wrong, I have tried to put the
script in /usr/bin as well but same result for all tasks -

TASK [Run a script via command line] *
The full traceback is:
  File

"/tmp/ansible_ansible.legacy.command_payload_p_z2bc7h/ansible_ansible.legacy.command_payload.zip/ansible/module_utils/basic.py",
line 2050, in run_command
    cmd = subprocess.Popen(args, **kwargs)
          
  File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.11/subprocess.py", line 1901, in
_execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
fatal: [100.91.187.42]: FAILED! => {
    "changed": false,
    "cmd": "./power_consumption.sh",
    "invocation": {
        "module_args": {
            "_raw_params": "./power_consumption.sh",
            "_uses_shell": false,
            "argv": null,
            "chdir": "/usr/src",
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true
        }
    },
    "msg": "[Errno 2] No such file or directory:
b'./power_consumption.sh'",
    "rc": 2,
    "stderr": "",
    "stderr_lines": [],
    "stdout": "",
    "stdout_lines": []
}

TASK [Run a script in another way] and TASK [Run a script]
The full traceback is:
NoneType: None
fatal: [100.91.187.42]: FAILED! => {
    "changed": true,
    "msg": "non-zero return code",
    "rc": 2,
    "stderr": "Shared connection to 100.91.187.42 closed.\r\n",
    "stderr_lines": [
        "Shared connection to 100.91.187.42 closed."
    ],
    "stdout":

"/root/.ansible/tmp/ansible-tmp-1724235551.658032-3341659-128056030829200/power_consumption.sh:
3: Syntax error: \"(\" unexpected\r\n",
    "stdout_lines": [

"/root/.ansible/tmp/ansible-tmp-1724235551.658032-3341659-128056030829200/power_consumption.sh:
3: Syntax error: \"(\" unexpected"
    ]
}

TASK [Run a shell command
fatal: [100.91.187.42]: FAILED! => {
    "changed": true,
    "cmd": "power_consumption.sh",
    "delta": "0:00:00.001867",
    "end": "2024-08-21 10:19:11.554061",
    "invocation": {
        "module_args": {
            "_raw_params": "power_consumption.sh",
   

Re: [ansible-project] Unable to execute shell script

2024-08-21 Thread Yogita Patil
I see, ok let me try that! , it runs via cli without it so that is why I
hadn't added it. I will try that, thanks guys!

On Wed, Aug 21, 2024 at 4:41 PM Dick Visser  wrote:

> On Wed, 21 Aug 2024 at 14:12, Yogita Patil 
> wrote:
> >
> > Yes yes I understand what you mean, and it does work if I add
> #!/bin/bash’  at the beginning of my foo.sh
>
> Yes, but your power consumption script ALSO needs to have the correct
> shebang.
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAF8BbLZTh0rXs%3DEu%3D0OBODKAdpr_MK9Eyt9bbfnw2FpOo5yt%2Bg%40mail.gmail.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAC15M2%2BB6%3DFzLxBZGXPf-QVbS_sYLcNnJVoLKoK4E%3DyB7aDniQ%40mail.gmail.com.


Re: [ansible-project] Unable to execute shell script

2024-08-21 Thread Dick Visser
On Wed, 21 Aug 2024 at 14:12, Yogita Patil  wrote:
>
> Yes yes I understand what you mean, and it does work if I add  #!/bin/bash’  
> at the beginning of my foo.sh

Yes, but your power consumption script ALSO needs to have the correct shebang.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAF8BbLZTh0rXs%3DEu%3D0OBODKAdpr_MK9Eyt9bbfnw2FpOo5yt%2Bg%40mail.gmail.com.


Re: [ansible-project] Unable to execute shell script

2024-08-21 Thread Yogita Patil
Yes yes I understand what you mean, and it does work if I add
#!/bin/bash’  at the beginning of my foo.sh

contents of foo.sh -
#!/bin/bash
echo "Hello world"

However my power consumption script fails. Any idea what I am doing wrong
there?

Many thanks for your help!

-Yogita.

On Wed, Aug 21, 2024 at 4:07 PM Stephen Maher  wrote:

> Hi,
>
> Your bash script must in include ‘#!/bin/bash’ to allow for its execution
> using bash hence the suggestion to add the executable verb to prove this
> was the case.
>
> Regards
>
>
>
> On 21 Aug 2024, at 11:25, Yogita Patil  wrote:
>
> The bash was just a trial, the is the script that I really care about
> running which runs perfectly from the command line -
> myScript.yml
>
> - name: Shell script test
>   hosts: all
>   tasks:
>
>  - name: Run a shell command
>ansible.builtin.shell: power_consumption.sh
>register: foo_result
>args:
>  chdir: /usr/src
>ignore_errors: true
>
>  - name: Run a script
>ansible.builtin.script:
>  cmd: /usr/src/power_consumption.sh
>ignore_errors: true
>
>  - name: Run a script in another way
>ansible.builtin.script: /usr/src/power_consumption.sh
>ignore_errors: true
>
>  - name: Run a script via command line
>ansible.builtin.command: ./power_consumption.sh
>args:
>  chdir: /usr/src
>ignore_errors: true
>
>
> # - name: Run a script second way
> #   ansible.builtin.script:
> #   cmd: /usr/src/power_consumption.sh
>
>  - name: Run a shell command using output of the previous task
>ansible.builtin.shell: /usr/src/bar.sh
>when: foo_result.rc == 5
>
>
> The contents of the power_consumption.sh script are -
>
> hostfqdn=$(hostname --fqdn)
> time=1
> declare T0=($(cat /sys/class/powercap/intel-rapl/*/energy_uj)); sleep
> $time; declare T1=($(cat /sys/class/powercap/intel-rapl/*/energy_uj))
> for i in "${!T0[@]}"; do echo - | awk "{printf \"%.1f W\",
> $((${T1[i]}-${T0[i]})) / $time / 1e6 }" >> $hostfqdn.txt ; done
>
>
> I have no idea what I am doing wrong, I have tried to put the script in
> /usr/bin as well but same result for all tasks -
>
> TASK [Run a script via command line] *
> The full traceback is:
>   File
> "/tmp/ansible_ansible.legacy.command_payload_p_z2bc7h/ansible_ansible.legacy.command_payload.zip/ansible/module_utils/basic.py",
> line 2050, in run_command
> cmd = subprocess.Popen(args, **kwargs)
>   
>   File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__
> self._execute_child(args, executable, preexec_fn, close_fds,
>   File "/usr/lib/python3.11/subprocess.py", line 1901, in _execute_child
> raise child_exception_type(errno_num, err_msg, err_filename)
> fatal: [100.91.187.42]: FAILED! => {
> "changed": false,
> "cmd": "./power_consumption.sh",
> "invocation": {
> "module_args": {
> "_raw_params": "./power_consumption.sh",
> "_uses_shell": false,
> "argv": null,
> "chdir": "/usr/src",
> "creates": null,
> "executable": null,
> "removes": null,
> "stdin": null,
> "stdin_add_newline": true,
> "strip_empty_ends": true
> }
> },
> "msg": "[Errno 2] No such file or directory:
> b'./power_consumption.sh'",
> "rc": 2,
> "stderr": "",
> "stderr_lines": [],
> "stdout": "",
> "stdout_lines": []
> }
>
> TASK [Run a script in another way] and TASK [Run a script]
> The full traceback is:
> NoneType: None
> fatal: [100.91.187.42]: FAILED! => {
> "changed": true,
> "msg": "non-zero return code",
> "rc": 2,
> "stderr": "Shared connection to 100.91.187.42 closed.\r\n",
> "stderr_lines": [
> "Shared connection to 100.91.187.42 closed."
> ],
> "stdout":
> "/root/.ansible/tmp/ansible-tmp-1724235551.658032-3341659-128056030829200/power_consumption.sh:
> 3: Syntax error: \"(\" unexpected\r\n",
> "stdout_lines": [
>
> "/root/.ansible/tmp/ansible-tmp-1724235551.658032-3341659-128056030829200/power_consumption.sh:
> 3: Syntax error: \"(\" unexpected"
> ]
> }
>
> TASK [Run a shell command
> fatal: [100.91.187.42]: FAILED! => {
> "changed": true,
> "cmd": "power_consumption.sh",
> "delta": "0:00:00.001867",
> "end": "2024-08-21 10:19:11.554061",
> "invocation": {
> "module_args": {
> "_raw_params": "power_consumption.sh",
> "_uses_shell": true,
> "argv": null,
> "chdir": "/usr/src",
> "creates": null,
> "executable": null,
> "removes": null,
> "stdin": null,
> "stdin_add_newline": true,
> "strip_empty_ends": true
> }
> },
> "msg": "non-zero return code",
> "rc": 127,
> "start": "2024-08-21 10:19:11.552194",
> "stderr": "/bin/sh: 1: 

Re: [ansible-project] Unable to execute shell script

2024-08-21 Thread Stephen Maher
Hi,

Your bash script must in include ‘#!/bin/bash’ to allow for its execution using 
bash hence the suggestion to add the executable verb to prove this was the case.

Regards



> On 21 Aug 2024, at 11:25, Yogita Patil  wrote:
> 
> The bash was just a trial, the is the script that I really care about running 
> which runs perfectly from the command line -
> myScript.yml
> 
> - name: Shell script test
>   hosts: all
>   tasks:
> 
>  - name: Run a shell command
>ansible.builtin.shell: power_consumption.sh
>register: foo_result
>args:
>  chdir: /usr/src
>ignore_errors: true
> 
>  - name: Run a script
>ansible.builtin.script:
>  cmd: /usr/src/power_consumption.sh
>ignore_errors: true
> 
>  - name: Run a script in another way
>ansible.builtin.script: /usr/src/power_consumption.sh
>ignore_errors: true
> 
>  - name: Run a script via command line
>ansible.builtin.command: ./power_consumption.sh
>args:
>  chdir: /usr/src
>ignore_errors: true
> 
> 
> # - name: Run a script second way
> #   ansible.builtin.script:
> #   cmd: /usr/src/power_consumption.sh
> 
>  - name: Run a shell command using output of the previous task
>ansible.builtin.shell: /usr/src/bar.sh
>when: foo_result.rc == 5
> 
> 
> The contents of the power_consumption.sh script are - 
> 
> hostfqdn=$(hostname --fqdn)
> time=1
> declare T0=($(cat /sys/class/powercap/intel-rapl/*/energy_uj)); sleep $time; 
> declare T1=($(cat /sys/class/powercap/intel-rapl/*/energy_uj))
> for i in "${!T0[@]}"; do echo - | awk "{printf \"%.1f W\", 
> $((${T1[i]}-${T0[i]})) / $time / 1e6 }" >> $hostfqdn.txt ; done
> 
> 
> I have no idea what I am doing wrong, I have tried to put the script in 
> /usr/bin as well but same result for all tasks -
> 
> TASK [Run a script via command line] *
> The full traceback is:
>   File 
> "/tmp/ansible_ansible.legacy.command_payload_p_z2bc7h/ansible_ansible.legacy.command_payload.zip/ansible/module_utils/basic.py",
>  line 2050, in run_command
> cmd = subprocess.Popen(args, **kwargs)
>   
>   File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__
> self._execute_child(args, executable, preexec_fn, close_fds,
>   File "/usr/lib/python3.11/subprocess.py", line 1901, in _execute_child
> raise child_exception_type(errno_num, err_msg, err_filename)
> fatal: [100.91.187.42]: FAILED! => {
> "changed": false,
> "cmd": "./power_consumption.sh",
> "invocation": {
> "module_args": {
> "_raw_params": "./power_consumption.sh",
> "_uses_shell": false,
> "argv": null,
> "chdir": "/usr/src",
> "creates": null,
> "executable": null,
> "removes": null,
> "stdin": null,
> "stdin_add_newline": true,
> "strip_empty_ends": true
> }
> },
> "msg": "[Errno 2] No such file or directory: b'./power_consumption.sh'",
> "rc": 2,
> "stderr": "",
> "stderr_lines": [],
> "stdout": "",
> "stdout_lines": []
> }
> 
> TASK [Run a script in another way] and TASK [Run a script]
> The full traceback is:
> NoneType: None
> fatal: [100.91.187.42]: FAILED! => {
> "changed": true,
> "msg": "non-zero return code",
> "rc": 2,
> "stderr": "Shared connection to 100.91.187.42 closed.\r\n",
> "stderr_lines": [
> "Shared connection to 100.91.187.42 closed."
> ],
> "stdout": 
> "/root/.ansible/tmp/ansible-tmp-1724235551.658032-3341659-128056030829200/power_consumption.sh:
>  3: Syntax error: \"(\" unexpected\r\n",
> "stdout_lines": [
> 
> "/root/.ansible/tmp/ansible-tmp-1724235551.658032-3341659-128056030829200/power_consumption.sh:
>  3: Syntax error: \"(\" unexpected"
> ]
> }
> 
> TASK [Run a shell command 
> fatal: [100.91.187.42]: FAILED! => {
> "changed": true,
> "cmd": "power_consumption.sh",
> "delta": "0:00:00.001867",
> "end": "2024-08-21 10:19:11.554061",
> "invocation": {
> "module_args": {
> "_raw_params": "power_consumption.sh",
> "_uses_shell": true,
> "argv": null,
> "chdir": "/usr/src",
> "creates": null,
> "executable": null,
> "removes": null,
> "stdin": null,
> "stdin_add_newline": true,
> "strip_empty_ends": true
> }
> },
> "msg": "non-zero return code",
> "rc": 127,
> "start": "2024-08-21 10:19:11.552194",
> "stderr": "/bin/sh: 1: power_consumption.sh: not found",
> "stderr_lines": [
> "/bin/sh: 1: power_consumption.sh: not found"
> ],
> "stdout": "",
> "stdout_lines": []
> }
> 
> 
> 
> 
> 
> 
> On Wed, Aug 21, 2024 at 12:36 PM Stephen Maher  > wrote:
> Hi,
> 
> This if often because your ’shell’ script 

Re: [ansible-project] Unable to execute shell script

2024-08-21 Thread Yogita Patil
The bash was just a trial, the is the script that I really care about
running which runs perfectly from the command line -
myScript.yml

- name: Shell script test
  hosts: all
  tasks:

 - name: Run a shell command
   ansible.builtin.shell: power_consumption.sh
   register: foo_result
   args:
 chdir: /usr/src
   ignore_errors: true

 - name: Run a script
   ansible.builtin.script:
 cmd: /usr/src/power_consumption.sh
   ignore_errors: true

 - name: Run a script in another way
   ansible.builtin.script: /usr/src/power_consumption.sh
   ignore_errors: true

 - name: Run a script via command line
   ansible.builtin.command: ./power_consumption.sh
   args:
 chdir: /usr/src
   ignore_errors: true


# - name: Run a script second way
#   ansible.builtin.script:
#   cmd: /usr/src/power_consumption.sh

 - name: Run a shell command using output of the previous task
   ansible.builtin.shell: /usr/src/bar.sh
   when: foo_result.rc == 5


The contents of the power_consumption.sh script are -

hostfqdn=$(hostname --fqdn)
time=1
declare T0=($(cat /sys/class/powercap/intel-rapl/*/energy_uj)); sleep
$time; declare T1=($(cat /sys/class/powercap/intel-rapl/*/energy_uj))
for i in "${!T0[@]}"; do echo - | awk "{printf \"%.1f W\",
$((${T1[i]}-${T0[i]})) / $time / 1e6 }" >> $hostfqdn.txt ; done


I have no idea what I am doing wrong, I have tried to put the script in
/usr/bin as well but same result for all tasks -

TASK [Run a script via command line] *
The full traceback is:
  File
"/tmp/ansible_ansible.legacy.command_payload_p_z2bc7h/ansible_ansible.legacy.command_payload.zip/ansible/module_utils/basic.py",
line 2050, in run_command
cmd = subprocess.Popen(args, **kwargs)
  
  File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.11/subprocess.py", line 1901, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
fatal: [100.91.187.42]: FAILED! => {
"changed": false,
"cmd": "./power_consumption.sh",
"invocation": {
"module_args": {
"_raw_params": "./power_consumption.sh",
"_uses_shell": false,
"argv": null,
"chdir": "/usr/src",
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true
}
},
"msg": "[Errno 2] No such file or directory: b'./power_consumption.sh'",
"rc": 2,
"stderr": "",
"stderr_lines": [],
"stdout": "",
"stdout_lines": []
}

TASK [Run a script in another way] and TASK [Run a script]
The full traceback is:
NoneType: None
fatal: [100.91.187.42]: FAILED! => {
"changed": true,
"msg": "non-zero return code",
"rc": 2,
"stderr": "Shared connection to 100.91.187.42 closed.\r\n",
"stderr_lines": [
"Shared connection to 100.91.187.42 closed."
],
"stdout":
"/root/.ansible/tmp/ansible-tmp-1724235551.658032-3341659-128056030829200/power_consumption.sh:
3: Syntax error: \"(\" unexpected\r\n",
"stdout_lines": [

"/root/.ansible/tmp/ansible-tmp-1724235551.658032-3341659-128056030829200/power_consumption.sh:
3: Syntax error: \"(\" unexpected"
]
}

TASK [Run a shell command
fatal: [100.91.187.42]: FAILED! => {
"changed": true,
"cmd": "power_consumption.sh",
"delta": "0:00:00.001867",
"end": "2024-08-21 10:19:11.554061",
"invocation": {
"module_args": {
"_raw_params": "power_consumption.sh",
"_uses_shell": true,
"argv": null,
"chdir": "/usr/src",
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true
}
},
"msg": "non-zero return code",
"rc": 127,
"start": "2024-08-21 10:19:11.552194",
"stderr": "/bin/sh: 1: power_consumption.sh: not found",
"stderr_lines": [
"/bin/sh: 1: power_consumption.sh: not found"
],
"stdout": "",
"stdout_lines": []
}






On Wed, Aug 21, 2024 at 12:36 PM Stephen Maher  wrote:

> Hi,
>
> This if often because your ’shell’ script has the incorrect shebang at the
> top. If its a bash script then add executable: /bin/bash and try again, or
> check your script.
>
> Cheers.
>
>
>
> On 21 Aug 2024, at 09:32, Yogita Patil  wrote:
>
> Thanks for the responses guys, but these are the errors I see -
>
> The full traceback is:
>   File
> "/tmp/ansible_ansible.legacy.command_payload_uk3ys11b/ansible_ansible.legacy.command_payload.zip/ansible/module_utils/basic.py",
> line 2050, in run_command
> cmd = subprocess.Popen(args, **kwargs)
>   
>   File 

Re: [ansible-project] Unable to execute shell script

2024-08-21 Thread Stephen Maher
Hi,

This if often because your ’shell’ script has the incorrect shebang at the top. 
If its a bash script then add executable: /bin/bash and try again, or check 
your script.

Cheers.



> On 21 Aug 2024, at 09:32, Yogita Patil  wrote:
> 
> Thanks for the responses guys, but these are the errors I see -
> 
> The full traceback is:
>   File 
> "/tmp/ansible_ansible.legacy.command_payload_uk3ys11b/ansible_ansible.legacy.command_payload.zip/ansible/module_utils/basic.py",
>  line 2050, in run_command
> cmd = subprocess.Popen(args, **kwargs)
>   
>   File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__
> self._execute_child(args, executable, preexec_fn, close_fds,
>   File "/usr/lib/python3.11/subprocess.py", line 1901, in _execute_child
> raise child_exception_type(errno_num, err_msg, err_filename)
> failed: [100.91.187.42] (item=./power_consumption.sh) => {
> "ansible_loop_var": "item",
> "changed": false,
> "cmd": "./power_consumption.sh",
> "invocation": {
> "module_args": {
> "_raw_params": "./power_consumption.sh",
> "_uses_shell": false,
> "argv": null,
> "chdir": "/usr/src/",
> "creates": null,
> "executable": null,
> "removes": null,
> "stdin": null,
> "stdin_add_newline": true,
> "strip_empty_ends": true
> }
> },
> "item": "./power_consumption.sh",
> "msg": "[Errno 8] Exec format error: b'./power_consumption.sh'",
> "rc": 8,
> "stderr": "",
> "stderr_lines": [],
> "stdout": "",
> "stdout_lines": []
> }
> 
> 
> I also create a simple foo.sh and tried to execute it like this, but here 
> also I get errors -
> foo.sh contents - 
> #!/bin/sh
> echo "Hello world"
> 
> My TestShell script yml looks like this -
> 
> - name: Shell script test
>   hosts: all
>   tasks:
> 
>  - name: Run a shell command and register its output as a variable
>ansible.builtin.shell: /usr/src/foo.sh
>register: foo_result
>ignore_errors: true
> 
>  - name: Run a shell command using output of the previous task
>ansible.builtin.shell: /usr/src/bar.sh
>when: foo_result.rc == 5
> 
> 
> Output of the above yml gives this error - 
> 
> fatal: [132.56.197.46]: FAILED! => {
> "changed": true,
> "cmd": "/usr/src/foo.sh",
> "delta": "0:00:00.002043",
> "end": "2024-08-21 08:32:06.317505",
> "invocation": {
> "module_args": {
> "_raw_params": "/usr/src/foo.sh",
> "_uses_shell": true,
> "argv": null,
> "chdir": null,
> "creates": null,
> "executable": null,
> "removes": null,
> "stdin": null,
> "stdin_add_newline": true,
> "strip_empty_ends": true
> }
> },
> "msg": "non-zero return code",
> "rc": 127,
> "start": "2024-08-21 08:32:06.315462",
> "stderr": "/bin/sh: 1: /usr/src/foo.sh: not found",
> "stderr_lines": [
> "/bin/sh: 1: /usr/src/foo.sh: not found"
> ],
> "stdout": "",
> "stdout_lines": []
> }
> 
> 
> On Mon, Aug 19, 2024 at 5:47 PM [email protected]  
> mailto:[email protected]>> wrote:
> 
> Create a var for script i.e.: script_path="/some/path/script" and use that 
> instead of hard coding path
> On Sunday, August 18, 2024 at 7:14:58 AM UTC-4 Yogita Patil wrote:
> Hi All,
> 
> I am simply unable to execute a shell script on the remote host - this is my 
> code (all other tasks run correctly except the execute task)
> 
> - name: Power consumption test
>   hosts: all
>   tasks:
> 
>  - name: Transfer the script
>ansible.builtin.copy:
>  src: power_consumption.sh
>  dest: /usr/src/power_consumption.sh
>  mode: '0777'
> 
>  - name: Execute the script
> #   command: ./usr/src/power_consumption.sh
>command: "{{ item }}"
>args:
>  chdir: "/usr/src/"
>with_items:
> - "./power_consumption.sh"
>ignore_errors: true
> 
>  - name: Remove shell script from remote server
>file:
>  path: /usr/src/power_consumption.sh
>  state: absent
> 
>  - name: Copy shell script output from remote server
>fetch:
>  src: /usr/src/{{ ansible_fqdn }}.txt
>  dest: /usr/src
>  mode: '0777'
>  with_fileglob:
>   _ "*.txt"
> 
> 
> I have also tried with the shell: , script: sh ways of executing the script 
> and none of them work, can someone tell me what I am doing wrong? TIA.
> 
> -- 
> 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 [email protected] 
> .
> To view 

Re: [ansible-project] Re: Unable to execute shell script

2024-08-21 Thread Yogita Patil
Thanks for the responses guys, but these are the errors I see -

The full traceback is:
  File
"/tmp/ansible_ansible.legacy.command_payload_uk3ys11b/ansible_ansible.legacy.command_payload.zip/ansible/module_utils/basic.py",
line 2050, in run_command
cmd = subprocess.Popen(args, **kwargs)
  
  File "/usr/lib/python3.11/subprocess.py", line 1024, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.11/subprocess.py", line 1901, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
failed: [100.91.187.42] (item=./power_consumption.sh) => {
"ansible_loop_var": "item",
"changed": false,
"cmd": "./power_consumption.sh",
"invocation": {
"module_args": {
"_raw_params": "./power_consumption.sh",
"_uses_shell": false,
"argv": null,
"chdir": "/usr/src/",
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true
}
},
"item": "./power_consumption.sh",
"msg": "[Errno 8] Exec format error: b'./power_consumption.sh'",
"rc": 8,
"stderr": "",
"stderr_lines": [],
"stdout": "",
"stdout_lines": []
}


I also create a simple foo.sh and tried to execute it like this, but here
also I get errors -
foo.sh contents -
#!/bin/sh
echo "Hello world"

My TestShell script yml looks like this -

- name: Shell script test
  hosts: all
  tasks:

 - name: Run a shell command and register its output as a variable
   ansible.builtin.shell: /usr/src/foo.sh
   register: foo_result
   ignore_errors: true

 - name: Run a shell command using output of the previous task
   ansible.builtin.shell: /usr/src/bar.sh
   when: foo_result.rc == 5


Output of the above yml gives this error -

fatal: [132.56.197.46]: FAILED! => {
"changed": true,
"cmd": "/usr/src/foo.sh",
"delta": "0:00:00.002043",
"end": "2024-08-21 08:32:06.317505",
"invocation": {
"module_args": {
"_raw_params": "/usr/src/foo.sh",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true
}
},
"msg": "non-zero return code",
"rc": 127,
"start": "2024-08-21 08:32:06.315462",
"stderr": "/bin/sh: 1: /usr/src/foo.sh: not found",
"stderr_lines": [
"/bin/sh: 1: /usr/src/foo.sh: not found"
],
"stdout": "",
"stdout_lines": []
}


On Mon, Aug 19, 2024 at 5:47 PM [email protected] 
wrote:

>
> Create a var for script i.e.: script_path="/some/path/script" and use that
> instead of hard coding path
> On Sunday, August 18, 2024 at 7:14:58 AM UTC-4 Yogita Patil wrote:
>
>> Hi All,
>>
>> I am simply unable to execute a shell script on the remote host - this is
>> my code (all other tasks run correctly except the execute task)
>>
>> - name: Power consumption test
>>   hosts: all
>>   tasks:
>>
>>  - name: Transfer the script
>>ansible.builtin.copy:
>>  src: power_consumption.sh
>>  dest: /usr/src/power_consumption.sh
>>  mode: '0777'
>>
>>  - name: Execute the script
>> #   command: ./usr/src/power_consumption.sh
>>command: "{{ item }}"
>>args:
>>  chdir: "/usr/src/"
>>with_items:
>> - "./power_consumption.sh"
>>ignore_errors: true
>>
>>  - name: Remove shell script from remote server
>>file:
>>  path: /usr/src/power_consumption.sh
>>  state: absent
>>
>>  - name: Copy shell script output from remote server
>>fetch:
>>  src: /usr/src/{{ ansible_fqdn }}.txt
>>  dest: /usr/src
>>  mode: '0777'
>>  with_fileglob:
>>   _ "*.txt"
>>
>>
>> I have also tried with the shell: , script: sh ways of executing the
>> script and none of them work, can someone tell me what I am doing wrong?
>> TIA.
>>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/8da4e506-2504-4724-b4e9-c1d45c61800dn%40googlegroups.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 

Re: [ansible-project] Dealing with list content

2024-08-21 Thread Nitesh Dudhe
Dear Alex,

For your output minimisation:
you can arrange your task like this:

- name: Collect list of VMs in cluster
  community.vmware.vmware_vm_info:
 validate_certs: false
  register: vm_list

- name: Print list
  ansible.builtin.debug:
 msg: "{{ item['guest_name'] }}"
  loop: "{{ vm_list.virtual_machines }}"
loop_control:
 label:  "Collected vm-name"  # either you put empty string or some
relevant string



output will be like this:

ok: [localhost] => (item=Collected vm-name)
msg": "server01"
ok: [localhost] => (item=Collected vm-name)
msg": "server02"
ok: [localhost] => (item=Collected vm-name)
msg": "server03"

no more unwanted text during the debug for each iteration:
eg.  (item={'guest_name': 'xx', 'guest_fullname': 'Microsoft Windows
Server 2022 (64-bit)', 'power_state': 'poweredOn', 'ip_address': 'xx',
'mac_address': ['xx'], 'uuid': 'xx', 'instance_uuid': 'xx',
'vm_network': {'xx': {'ipv4': ['xx'], 'ipv6': []}},
'esxi_hostname': 'xx', 'datacenter': 'xx', 'cluster': 'xx',
'resource_pool': None, 'attributes': {}, 'tags': [], 'folder': 'xx',
'moid': 'xx', 'datastore_url': [{'name': 'xx', 'url': 'xx'}],
'allocated': {}}) =>

I hope this helps


Regards
Nitesh Dudhe

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAGPd1LmKTJvoB5b3sWauUa6KBFpUKPVUTbPLkqBsC2KKdoYhGw%40mail.gmail.com.


Re: [ansible-project] Re: Dealing with list content

2024-08-20 Thread Vladimir Botka
On Tue, 20 Aug 2024 16:16:17 -0600
Alex Wanderley  wrote:

> Hi,
> 
> OK, answering my own question, I was able to send the parsed vm_list
> content to a file using this task:
> 
>  - name: Copy list to file
>ansible.builtin.lineinfile:
>   dest: 
>   line: "{{ item['guest_name'] }}"
>   state: present
>   create: yes
>loop: "{{ vm_list.virtual_machines }}"
> 
> There would be a different/better way of accomplishing that...?

Try this

  - copy:
  dest: 
  content: |
{% for i in vm_list.virtual_machines %}
{{ i.guest_name }}
{% endfor %}

See
https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_templating.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20240821005716.701bac09%40gmail.com.


pgp8Vv9Q_CxrZ.pgp
Description: OpenPGP digital signature


Re: [ansible-project] Ansible user privilege and application location

2024-08-20 Thread Brian Coca
1. remote_user is the 'user you log in as' on the remote, mostly used
by ssh and similar connection plugins
2. When using sudo (substitute user do) 'the current user' (normally
remote/login in user) BECOMES the 'substitute user' to run a
command(s), that is what become_user allows you to specify. This is
what normally happens: sudo -u   (by default
sudo will use `-u root` if you omit -u)
3. That means you did not change to 'user home' aka `~/` or `$HOME`
(also happens when you `cd` without an argument), Ansible, by default,
operates on the "current effective user"'s home to handle permissions,
as you can become users other than root and those normally cannot
write to the  remote/login user's home


-- 
--
Brian Coca (he/him/they/them)

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7dN4dtBtwJbByeDzptng4Qc42q5hNEP5sibUNN_3cAjgg%40mail.gmail.com.


Re: [ansible-project] Enable fact caching per play(book) ?

2024-08-19 Thread Brian Coca
No


-- 
--
Brian Coca (he/him/they/them)

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7c8CbQJ2wSW62d%3DZ94YV9vSZQ8hHKg1DfS%2BNXMb8_bbOQ%40mail.gmail.com.


Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-19 Thread Garri Djavadyan
Hi Everyone,

I believe I found the reason why the Python binaries supplied by the
Debian team are not affected. It is well explained in Debian bug
report #1026802 [1]:

"Starting with Python 3.10, with the default configuration
("--with-ssl-default-suites=python"), Python not only enforces its own
cipher list but also requires TLS1.2 as a minimal protocol version."


I checked both Python versions, supplied by Debian and Python, and see
that the former indeed sticks to OpenSSL defaults:

-BEGIN debian:bookworm-slim-
$ python3 -m sysconfig | egrep -o 'with-ssl\S+'
with-ssl-default-suites=openssl'

$ python3 -m sysconfig | grep DEFAULT_CIPHERS
PY_SSL_DEFAULT_CIPHERS = "2"
-END debian:bookworm-slim-

-BEGIN python:3-slim-
$ python3 -m sysconfig | egrep -o 'with-ssl\S+'
$

$ python3 -m sysconfig | grep DEFAULT_CIPHERS
PY_SSL_DEFAULT_CIPHERS = "1"
-END python:3-slim-


Below are some details from the "ssl" module sources [2] about the
macros PY_SSL_DEFAULT_CIPHERS:

-BEGIN C-
#elif PY_SSL_DEFAULT_CIPHERS == 1
/* Python custom selection of sensible cipher suites
 * @SECLEVEL=2: security level 2 with 112 bits minimum security (e.g.
2048 bits RSA key)
 * ECDH+*: enable ephemeral elliptic curve Diffie-Hellman
 * DHE+*: fallback to ephemeral finite field Diffie-Hellman
 * encryption order: AES AEAD (GCM), ChaCha AEAD, AES CBC
 * !aNULL:!eNULL: really no NULL ciphers
 * !aDSS: no authentication with discrete logarithm DSA algorithm
 * !SHA1: no weak SHA1 MAC
 * !AESCCM: no CCM mode, it's uncommon and slow
 *
 * Based on Hynek's excellent blog post (update 2021-02-11)
 * https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
 */
  #define PY_SSL_DEFAULT_CIPHER_STRING
"@SECLEVEL=2:ECDH+AESGCM:ECDH+CHACHA20:ECDH+AES:DHE+AES:!aNULL:!eNULL:!aDSS:!SHA1:!AESCCM"
  #ifndef PY_SSL_MIN_PROTOCOL
#define PY_SSL_MIN_PROTOCOL TLS1_2_VERSION
  #endif
#elif PY_SSL_DEFAULT_CIPHERS == 2
/* Ignored in SSLContext constructor, only used to as
_ssl.DEFAULT_CIPHER_STRING */
  #define PY_SSL_DEFAULT_CIPHER_STRING SSL_DEFAULT_CIPHER_LIST
-END C-


Now it is totally clear why the default OpenSSL config file
"/etc/ssl/openssl.cnf" and the environment variable OPENSSL_CONF are
ignored by the officially distributed Python binaries.

And yes, @Stephen, OPENSSL_CONF set in Ansible playbooks is very well
respected by "ansible.builtin.uri" at least in the environments with
Python versions distributed by the Debian team.

Thank you everyone who contributed to this thread!


Regards,
Garri


[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1026802
[2] https://github.com/python/cpython/blob/main/Modules/_ssl.c


Op ma 19 aug 2024 10:37 schreef Garri Djavadyan :

> Hi Dick,
>
> Indeed, the problem is only manifested when OS-independent Python 3 is
> used. Even though, Python 3.12.5 is supplied with the python:3-slim image,
> I see the same issues with python:3.11.2-slim image.
>
> I do not see any issues when install ansible-core into OS-managed Python
> environment in Debian 12. It seems to me that the Debian team applied some
> local patches to the upstream python distribution to make it work. Some
> more investigation is needed, of course.
>
> Thank you.
>
> Regards,
> Garri
>
> Op ma 19 aug 2024 09:53 schreef Dick Visser :
>
>>
>> On Mon, 19 Aug 2024 at 00:51, Garri Djavadyan 
>> wrote:
>>
>>> Then it seems indeed a local problem of mine. In my case, Ansible is
>>> executed in a Docker container python:3-slim, which is based on
>>> debian:bookworm-slim. Within the container, 'ansible==10.*' is
>>> installed into a normal user's directory with pip, and Ansible commands
>>> are executed on behalf of that normal user.
>>
>>
>> I can confirm things also work OK in a debian:bookworm-slim container.
>> So I guess there must be something specific with the python container
>>
>> Dick
>>
>> --
>> 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 [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/CAF8BbLYWvgdmAPwSYz5%3DG8pKKPc7XWJzOjMaFyqj19aVGXrAtw%40mail.gmail.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAAG9kiqR77mOggeeWNuSypqY5WeKp%2B6Xd8zXi%3DW9WQPkuy6uxA%40mail.gmail.com.


Re: [ansible-project] Ansible templates. Joining item vars on one line with static text.

2024-08-19 Thread Michael Starling
Thank you both for the suggestions. Much appreciated.

On Sun, Aug 18, 2024 at 12:05 PM Vladimir Botka  wrote:

> On Sun, 18 Aug 2024 15:11:11 +0100
> Will McDonald  wrote:
>
> > There may be more elegant ways to achieve this
>
> The below declaration should to the job
>
> seeds: "{{ ansible_play_hosts |
>difference([inventory_hostname]) |
>map('extract', hostvars, 'ansible_host') |
>product([':2113']) |
>map('join') |
>join(',') }}"
>
> > {%- set seeds = [] %}
> > {%- for host in ansible_play_hosts %}
> >   {%- if host != inventory_hostname %}
> > {{ seeds.append(hostvars[host]['ansible_host'] ~ ':2113') }}
> >   {%- endif %}
> > {%- endfor %}
> >
> > GossipSeed: {{ seeds | join(',') }}
>
> For example, given the inventory
>
>
>   shell> cat hosts
>   host_A ansible_host=10.1.0.51
>   host_B ansible_host=10.1.0.52
>   host_C ansible_host=10.1.0.53
>
> the below play
>
>   - hosts: all
> vars:
>   seeds: "{{ ansible_play_hosts |
>  difference([inventory_hostname]) |
>  map('extract', hostvars, 'ansible_host') |
>  product([':2113']) |
>  map('join') |
>  join(',') }}"
> tasks:
>   - debug:
>   var: seeds
>
> gives (abridged)
>
> ok: [host_A] =>
>   seeds: 10.1.0.53:2113,10.1.0.52:2113
> ok: [host_B] =>
>   seeds: 10.1.0.53:2113,10.1.0.51:2113
> ok: [host_C] =>
>   seeds: 10.1.0.51:2113,10.1.0.52:2113
>
> HTH,
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/20240818180500.6cbdd318%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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAD8F6EmpSMCgxg3GfEuP-q2KR%2BX%2Bwtprs%3DiyNqid%2BdgQW7iiRg%40mail.gmail.com.


Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-19 Thread Garri Djavadyan
Hi Dick,

Indeed, the problem is only manifested when OS-independent Python 3 is
used. Even though, Python 3.12.5 is supplied with the python:3-slim image,
I see the same issues with python:3.11.2-slim image.

I do not see any issues when install ansible-core into OS-managed Python
environment in Debian 12. It seems to me that the Debian team applied some
local patches to the upstream python distribution to make it work. Some
more investigation is needed, of course.

Thank you.

Regards,
Garri

Op ma 19 aug 2024 09:53 schreef Dick Visser :

>
> On Mon, 19 Aug 2024 at 00:51, Garri Djavadyan 
> wrote:
>
>> Then it seems indeed a local problem of mine. In my case, Ansible is
>> executed in a Docker container python:3-slim, which is based on
>> debian:bookworm-slim. Within the container, 'ansible==10.*' is
>> installed into a normal user's directory with pip, and Ansible commands
>> are executed on behalf of that normal user.
>
>
> I can confirm things also work OK in a debian:bookworm-slim container.
> So I guess there must be something specific with the python container
>
> Dick
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAF8BbLYWvgdmAPwSYz5%3DG8pKKPc7XWJzOjMaFyqj19aVGXrAtw%40mail.gmail.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAAG9kiraYeXj7cmtFs1G%2Bieu3MerYH-1XGO%3DF-eNeZ3amC-2Pg%40mail.gmail.com.


Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-19 Thread Dick Visser
On Mon, 19 Aug 2024 at 00:51, Garri Djavadyan  wrote:

> Then it seems indeed a local problem of mine. In my case, Ansible is
> executed in a Docker container python:3-slim, which is based on
> debian:bookworm-slim. Within the container, 'ansible==10.*' is
> installed into a normal user's directory with pip, and Ansible commands
> are executed on behalf of that normal user.


I can confirm things also work OK in a debian:bookworm-slim container.
So I guess there must be something specific with the python container

Dick

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAF8BbLYWvgdmAPwSYz5%3DG8pKKPc7XWJzOjMaFyqj19aVGXrAtw%40mail.gmail.com.


Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-18 Thread Garri Djavadyan
Hi Dick,

Hmm, very interesting ... Thank you so much for your replication
efforts!

Then it seems indeed a local problem of mine. In my case, Ansible is
executed in a Docker container python:3-slim, which is based on
debian:bookworm-slim. Within the container, 'ansible==10.*' is
installed into a normal user's directory with pip, and Ansible commands
are executed on behalf of that normal user.

I will check if this setup somehow affects the TLS negotiation. I will
update the thread once I find the culprit.

Thank you.

Regards,
Garri


On Sat, 2024-08-17 at 13:09 +0200, Dick Visser wrote:
> Hii
> I tried to replicate what you see. To help debug I spun up an old web
> server that is only doing TLSv1.
> Then, on a clean Debian 12 VM, initially the URL fails to fetch with
> curl, as expected:
> 
> (venv) vagrant@debian-12:~$ curl -Ikv https://tlsv1.tienhuis.nl
> *   Trying [2001:648:2ffc:1225:a800:4ff:fec1:7353]:443...
> * Connected to tlsv1.tienhuis.nl
> (2001:648:2ffc:1225:a800:4ff:fec1:7353) port 443 (#0)
> * ALPN: offers h2,http/1.1
> * TLSv1.3 (OUT), TLS handshake, Client hello (1):
> * TLSv1.3 (IN), TLS handshake, Server hello (2):
> * TLSv1.0 (IN), TLS handshake, Certificate (11):
> * TLSv1.0 (IN), TLS handshake, Server key exchange (12):
> * TLSv1.0 (OUT), TLS alert, internal error (592):
> * OpenSSL/3.0.13: error:0A00014D:SSL routines::legacy sigalg
> disallowed or unsupported
> * Closing connection 0
> curl: (35) OpenSSL/3.0.13: error:0A00014D:SSL routines::legacy sigalg
> disallowed or unsupported
> 
> Likewise, this playbook:
> 
> ---
> - name: legacy test
>   hosts: localhost
>   gather_facts: false
>   connection: local
>   tasks:
>     - name: fetch URL
>       ansible.builtin.uri:
>         url: https://tlsv1.tienhuis.nl
>         validate_certs: false
>       register: out
>     - ansible.builtin.debug: var=out
> 
> also fails at the uri task:
> 
> TASK [fetch URL]
> *
> 
> fatal: [localhost]: FAILED! => {"changed": false, "elapsed": 0,
> "msg": "Status code was -1 and not [200]: Request failed:  error [SSL] legacy sigalg disallowed or unsupported (_ssl.c:992)>",
> "redirected": false, "status": -1, "url":
> "https://tlsv1.tienhuis.nl"}
> 
> Replacing /etc/ssl/openssl.cnf with the small version that you have 
> 
> (venv) vagrant@debian-12:~$ cat /etc/ssl/openssl.cnf 
> openssl_conf = openssl_init
> [openssl_init]
> ssl_conf = ssl_sect
> [ssl_sect]
> system_default = system_default_sect
> [system_default_sect]
> MinProtocol = TLSv1
> CipherString = DEFAULT@SECLEVEL=0
> Options = UnsafeLegacyRenegotiation
> 
> makes curl work:
> 
> (venv) vagrant@debian-12:~$ curl -Ikv https://tlsv1.tienhuis.nl
> *   Trying [2001:648:2ffc:1225:a800:4ff:fec1:7353]:443...
> * Connected to tlsv1.tienhuis.nl
> (2001:648:2ffc:1225:a800:4ff:fec1:7353) port 443 (#0)
> * ALPN: offers h2,http/1.1
> * TLSv1.3 (OUT), TLS handshake, Client hello (1):
> * TLSv1.3 (IN), TLS handshake, Server hello (2):
> * TLSv1.0 (IN), TLS handshake, Certificate (11):
> * TLSv1.0 (IN), TLS handshake, Server key exchange (12):
> * TLSv1.0 (IN), TLS handshake, Server finished (14):
> * TLSv1.0 (OUT), TLS handshake, Client key exchange (16):
> * TLSv1.0 (OUT), TLS change cipher, Change cipher spec (1):
> * TLSv1.0 (OUT), TLS handshake, Finished (20):
> * TLSv1.0 (IN), TLS handshake, Finished (20):
> * SSL connection using TLSv1 / ECDHE-RSA-AES256-SHA
> * ALPN: server did not agree on a protocol. Uses default.
> * Server certificate:
> *  subject: CN=tlsv1.tienhuis.nl
> *  start date: Aug 17 10:25:11 2024 GMT
> *  expire date: Jan 17 10:25:11 2038 GMT
> *  issuer: CN=tlsv1.tienhuis.nl
> *  SSL certificate verify result: self-signed certificate (18),
> continuing anyway.
> * using HTTP/1.x
> > HEAD / HTTP/1.1
> > Host: tlsv1.tienhuis.nl
> > User-Agent: curl/7.88.1
> > Accept: */*
> > 
> < HTTP/1.1 200 OK
> 
> BUT, it also makes the uri task in the ansible playbook work:
> 
> TASK [ansible.builtin.debug]
> *
> 
> ok: [localhost] => {
>     "out": {
>         "accept_ranges": "bytes",
>         "changed": false,
>         "connection": "close",
>         "content_length": "10701",
>         "content_type": "text/html",
>         "cookies": {},
>         "cookies_string": "",
>         "date": "Sat, 17 Aug 2024 11:02:40 GMT",
>         "elapsed": 0,
>         "etag": "\"29cd-61fde5e24e55f\"",
>         "failed": false,
>         "last_modified": "Sat, 17 Aug 2024 10:16:22 GMT",
>         "msg": "OK (10701 bytes)",
>         "redirected": false,
>         "server": "Apache/2.4.10 (Debian)",
>         "status": 200,
>         "url": "https://tlsv1.tienhuis.nl";,
>         "vary": "Accept-Encoding"
>     }
> }
> 
> This seems to indicate a local problem somewhere on your side
> FYI, on my control node:
> 
> (venv) 

Re: [ansible-project] Unable to execute shell script

2024-08-18 Thread Dick Visser
Without any real data it's impossible to tell.
Can you at a minimum post the error message?

Sent from Gmail Mobile


On Sun, Aug 18, 2024 at 13:14 Yogita Patil  wrote:

> Hi All,
>
> I am simply unable to execute a shell script on the remote host - this is
> my code (all other tasks run correctly except the execute task)
>
> - name: Power consumption test
>   hosts: all
>   tasks:
>
>  - name: Transfer the script
>ansible.builtin.copy:
>  src: power_consumption.sh
>  dest: /usr/src/power_consumption.sh
>  mode: '0777'
>
>  - name: Execute the script
> #   command: ./usr/src/power_consumption.sh
>command: "{{ item }}"
>args:
>  chdir: "/usr/src/"
>with_items:
> - "./power_consumption.sh"
>ignore_errors: true
>
>  - name: Remove shell script from remote server
>file:
>  path: /usr/src/power_consumption.sh
>  state: absent
>
>  - name: Copy shell script output from remote server
>fetch:
>  src: /usr/src/{{ ansible_fqdn }}.txt
>  dest: /usr/src
>  mode: '0777'
>  with_fileglob:
>   _ "*.txt"
>
>
> I have also tried with the shell: , script: sh ways of executing the
> script and none of them work, can someone tell me what I am doing wrong?
> TIA.
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/7b120440-da9b-483a-965f-98cc9ab3f280n%40googlegroups.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAF8BbLZ_hvBiMiKOfBD3SzitJ1p0Q2znd_%2B%2BLb4%2BHVFSxm0EKw%40mail.gmail.com.


Re: [ansible-project] Ansible templates. Joining item vars on one line with static text.

2024-08-18 Thread Vladimir Botka
On Sun, 18 Aug 2024 15:11:11 +0100
Will McDonald  wrote:

> There may be more elegant ways to achieve this

The below declaration should to the job

seeds: "{{ ansible_play_hosts |
   difference([inventory_hostname]) |
   map('extract', hostvars, 'ansible_host') |
   product([':2113']) |
   map('join') |
   join(',') }}"

> {%- set seeds = [] %}
> {%- for host in ansible_play_hosts %}
>   {%- if host != inventory_hostname %}
> {{ seeds.append(hostvars[host]['ansible_host'] ~ ':2113') }}
>   {%- endif %}
> {%- endfor %}
> 
> GossipSeed: {{ seeds | join(',') }}

For example, given the inventory


  shell> cat hosts
  host_A ansible_host=10.1.0.51
  host_B ansible_host=10.1.0.52
  host_C ansible_host=10.1.0.53

the below play

  - hosts: all
vars:
  seeds: "{{ ansible_play_hosts |
 difference([inventory_hostname]) |
 map('extract', hostvars, 'ansible_host') |
 product([':2113']) |
 map('join') |
 join(',') }}"
tasks:
  - debug:
  var: seeds

gives (abridged)

ok: [host_A] => 
  seeds: 10.1.0.53:2113,10.1.0.52:2113
ok: [host_B] => 
  seeds: 10.1.0.53:2113,10.1.0.51:2113
ok: [host_C] => 
  seeds: 10.1.0.51:2113,10.1.0.52:2113

HTH,

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20240818180500.6cbdd318%40gmail.com.


pgpKnie3teTXh.pgp
Description: OpenPGP digital signature


Re: [ansible-project] Ansible templates. Joining item vars on one line with static text.

2024-08-18 Thread Vladimir Botka
On Sun, 18 Aug 2024 09:45:11 -0400
Michael Starling  wrote:

> ldapservers:
> - server1
> - server2
>
> I would like the resulting file to look like this:
> 
> URI ldap://server1/ ldap://server2/

Put the below declarations as appropriate

ldapservers: [server1, server2]
uri: "{{ ['ldap://'] |
 product(ldapservers) | map('join') |
 product(['/'])| map('join') |
 join(' ') }}"

Then, the template is trivial

- copy:
content: |
  URI {{ uri }}
dest: /tmp/uri.test

gives what you want

shell> cat /tmp/uri.test 
URI ldap://server1/ ldap://server2/

HTH,

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20240818175809.65c373f3%40gmail.com.


pgphYeKEAgDzW.pgp
Description: OpenPGP digital signature


Re: [ansible-project] Ansible templates. Joining item vars on one line with static text.

2024-08-18 Thread Will McDonald
There may be more elegant ways to achieve this, but I had a similar
requirement from some Eventstore config a while back and ended up with a
construct like:

# Construct each GossipSeed from ansible_play_hosts minus the inventory_host
{%- set seeds = [] %}
{%- for host in ansible_play_hosts %}
  {%- if host != inventory_hostname %}
{{ seeds.append(hostvars[host]['ansible_host'] ~ ':2113') }}
  {%- endif %}
{%- endfor %}

GossipSeed: {{ seeds | join(',') }}

In your case you could maybe do something like (untested):

# Construct list of LDAP server URIs
{%- set ldap_sever_list = [] %}
{%- for server in ldapservers %}
{{ ldap_sever_list.append('ldap://' ~ server ~ '/') }}
{%- endfor %}

URI: {{ ldap_server_list | join(',') }}


On Sun, 18 Aug 2024 at 14:45, Michael Starling 
wrote:

> Hello.
>
> Consider I have this variable list that can contain as little as 1 and up
> to 4 items.
>
> ldapservers:
> - server1
> - server2
>
>
> Consider this line in my ldap.conf template.
>
> URI ldap://{{ ldapservers(' ') }}/
>
>
> I would like the resulting file to look like this:
>
> URI ldap://server1/ ldap://server2/
>
> I know I can use "join" with something like this, but how do I keep the
> "URI" the " ldap://"; and the trailing "/" consistent without adding them to
> the variable.
>
> URI ldap://{{ ldap_srv_fqdn|join(' ') }}/
>
> Thanks in advance.
>
> Mike
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAD8F6EndrOwpvRuOYWXauBQQ4xUs7-piNzwzNT1867AtaZLXmg%40mail.gmail.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAKtKohRtu2ODVg%3DzPrRQC-L%2BbGA5eBm9juapG732GtrkdoL-_Q%40mail.gmail.com.


Re: [ansible-project] Ansible loop issue

2024-08-18 Thread HBach
Thanks, Todd.  

According the docs, the name: param is for the virtual machine and 
hostname: under customization: is for setting the hostname.  I was able to 
register the stdout of the task, capturing it 
to a variable.   The substitutions are being made.  

  "instance": {
"module_hw": true,
"hw_name": "rheltest0816d",
"hw_power_status": "poweredOn",

-and- 

  "customization": {
"existing_vm": true,
"dns_servers": [
  "redacted",
  "redacted"
],
"domain": "",
"hostname": "rheltest0816d",

The hostname is not being updated on the vm though and that's causing a 
glitch downstream in the next job template in the workflow.  
I'm not sure if I should move the state: param near the beginning of the 
task.  

On Friday, August 16, 2024 at 12:16:40 PM UTC-6 Todd Lewis wrote:

> I'm inclined to believe someone is confused by the two hostname: 
> parameters, and would need to see some job log evidence supporting the 
> claim that "the sub[stitution] is being made for name: but not for 
> hostname:." In any case, something from the job log would/should be 
> informative.
>
> I've found in situations like this it's helpful to change to module to 
> ansible.builtin.debug: immediately followed by msg: |. You'd then need to 
> play with indentation a little to make it informative.
> On 8/16/24 1:52 PM, HBach wrote:
>
> Hi, Community,  
>
> I am passing in a list, 'vmware_hosts', to the loop in the following task 
> in order to substitute values for the name: and hostname: parameters.  I 
> have found only the sub is being made for name: but not for hostname:.  
>
> - name: Set powerstate of a virtual machine to poweron
>   community.vmware.vmware_guest:
> hostname: "{{ vc_host_id }}"
> username: "{{ username }}"
> password: "{{ survey_password }}"
> name: "{{ item }}"
> customization:
>   existing_vm: true
>   dns_servers:
>   - "{{ dns_ns1 }}"
>   - "{{ dns_ns2 }}"
>   hostname: "{{ item }}"
> state: poweredon
> wait_for_ip_address: true
>   loop: "{{ vmware_hosts }}"
>   register: vm_state
>   delegate_to: localhost
>
> For each iteration of the loop, i.e. a different host, I need these two 
> parameters to hold the same value.  
>
> What am I missing here?  
>
> Thanks!  
>
> -- 
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/832cd4cf-942a-48c6-b73c-25a7f48a018an%40googlegroups.com
>  
> 
> .
>
>
> -- 
> Todd
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c113cb06-d40c-42f0-9176-d40ddef4ac0fn%40googlegroups.com.


Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-17 Thread Dick Visser
Hii
I tried to replicate what you see. To help debug I spun up an old web
server that is only doing TLSv1.
Then, on a clean Debian 12 VM, initially the URL fails to fetch with curl,
as expected:

(venv) vagrant@debian-12:~$ curl -Ikv https://tlsv1.tienhuis.nl
*   Trying [2001:648:2ffc:1225:a800:4ff:fec1:7353]:443...
* Connected to tlsv1.tienhuis.nl (2001:648:2ffc:1225:a800:4ff:fec1:7353)
port 443 (#0)
* ALPN: offers h2,http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.0 (IN), TLS handshake, Certificate (11):
* TLSv1.0 (IN), TLS handshake, Server key exchange (12):
* TLSv1.0 (OUT), TLS alert, internal error (592):
* OpenSSL/3.0.13: error:0A00014D:SSL routines::legacy sigalg disallowed or
unsupported
* Closing connection 0
curl: (35) OpenSSL/3.0.13: error:0A00014D:SSL routines::legacy sigalg
disallowed or unsupported

Likewise, this playbook:

---
- name: legacy test
  hosts: localhost
  gather_facts: false
  connection: local
  tasks:
- name: fetch URL
  ansible.builtin.uri:
url: https://tlsv1.tienhuis.nl
validate_certs: false
  register: out
- ansible.builtin.debug: var=out

also fails at the uri task:

TASK [fetch URL]
*
fatal: [localhost]: FAILED! => {"changed": false, "elapsed": 0, "msg":
"Status code was -1 and not [200]: Request failed: ", "redirected":
false, "status": -1, "url": "https://tlsv1.tienhuis.nl"}

Replacing /etc/ssl/openssl.cnf with the small version that you have

(venv) vagrant@debian-12:~$ cat /etc/ssl/openssl.cnf
openssl_conf = openssl_init
[openssl_init]
ssl_conf = ssl_sect
[ssl_sect]
system_default = system_default_sect
[system_default_sect]
MinProtocol = TLSv1
CipherString = DEFAULT@SECLEVEL=0
Options = UnsafeLegacyRenegotiation

makes curl work:

(venv) vagrant@debian-12:~$ curl -Ikv https://tlsv1.tienhuis.nl
*   Trying [2001:648:2ffc:1225:a800:4ff:fec1:7353]:443...
* Connected to tlsv1.tienhuis.nl (2001:648:2ffc:1225:a800:4ff:fec1:7353)
port 443 (#0)
* ALPN: offers h2,http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.0 (IN), TLS handshake, Certificate (11):
* TLSv1.0 (IN), TLS handshake, Server key exchange (12):
* TLSv1.0 (IN), TLS handshake, Server finished (14):
* TLSv1.0 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.0 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.0 (OUT), TLS handshake, Finished (20):
* TLSv1.0 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1 / ECDHE-RSA-AES256-SHA
* ALPN: server did not agree on a protocol. Uses default.
* Server certificate:
*  subject: CN=tlsv1.tienhuis.nl
*  start date: Aug 17 10:25:11 2024 GMT
*  expire date: Jan 17 10:25:11 2038 GMT
*  issuer: CN=tlsv1.tienhuis.nl
*  SSL certificate verify result: self-signed certificate (18), continuing
anyway.
* using HTTP/1.x
> HEAD / HTTP/1.1
> Host: tlsv1.tienhuis.nl
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 200 OK

BUT, it also makes the uri task in the ansible playbook work:

TASK [ansible.builtin.debug]
*
ok: [localhost] => {
"out": {
"accept_ranges": "bytes",
"changed": false,
"connection": "close",
"content_length": "10701",
"content_type": "text/html",
"cookies": {},
"cookies_string": "",
"date": "Sat, 17 Aug 2024 11:02:40 GMT",
"elapsed": 0,
"etag": "\"29cd-61fde5e24e55f\"",
"failed": false,
"last_modified": "Sat, 17 Aug 2024 10:16:22 GMT",
"msg": "OK (10701 bytes)",
"redirected": false,
"server": "Apache/2.4.10 (Debian)",
"status": 200,
"url": "https://tlsv1.tienhuis.nl";,
"vary": "Accept-Encoding"
}
}

This seems to indicate a local problem somewhere on your side
FYI, on my control node:

(venv) vagrant@debian-12:~$ ansible --version
ansible [core 2.17.3]
  config file = None
  configured module search path =
['/home/vagrant/.ansible/plugins/modules',
'/usr/share/ansible/plugins/modules']
  ansible python module location =
/home/vagrant/venv/lib/python3.11/site-packages/ansible
  ansible collection location =
/home/vagrant/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/vagrant/venv/bin/ansible
  python version = 3.11.2 (main, May  2 2024, 11:59:08) [GCC 12.2.0]
(/home/vagrant/venv/bin/python3)
  jinja version = 3.1.4
  libyaml = True
(venv) vagrant@debian-12:~$ pip list
Package  Version
 ---
ansible-core 2.17.3
cffi 1.17.0
cryptography 43.0.0
Jinja2   3.1.4
MarkupSafe   2.1.5
packaging24.1
pip  24.2
pycparser2.22
PyYAML   6.0.2
resolvelib   1.0.1
setuptools   66.1.1
wheel0.44.0
(venv) vagrant@debian-12:~$ openssl 

Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-16 Thread Garri Djavadyan
Hi Dick, Walter, and all,

Dick, I totally agree that patching Ansible to support insecure
protocols should be discouraged in general, and I am totally fine to
continue using my current curl-based playbook until the legacy devices
are decommissioned. I was just curious if it would be possible to use
'ansible.builtin.uri' in an unsafe OpenSSL context without touching the
Ansible code. 

Walter, as far as I know, Linux kernel's TLS sockets (ktls) [1] only
provide encryption offloading capabilities to the user space libraries,
such as OpenSSL. As far as I can see, the handshake still should be
handled by the user space library.

As far as I know, 'ansible.builtin.uri' depends on the Python standard
library's 'urllib' [2], which depends on the 'ssl' module [3], also
from the standard library. The latter, depends on the user space
OpenSSL library.

Also, as I mentioned before, I can successfully talk to my legacy
devices using "curl" and loosened OpenSSL configuration, that I shared
earlier, from the same Debian 12.6 system. Therefore, I do not think
the kernel prohibits 'uri' from negotiating TLS 1.0 connections.

Thank you.

Regards,
Garri


[1] https://www.kernel.org/doc/html/latest/networking/tls.html
[2]
https://github.com/ansible/ansible/blob/v2.17.3/lib/ansible/module_utils/urls.py#L54
[3] https://docs.python.org/3/library/ssl.html


On Fri, 2024-08-16 at 11:13 +, 'Rowe, Walter P. (Fed)' via Ansible
Project wrote:
> If the kernel / OS won't allow lowering the TLS then a custom
> openssl.conf likely won't either. You can't override the kernel / OS
> to lower security.
> 
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services Division
> Mobile: 202.355.4123 
> 
> > On Aug 16, 2024, at 5:23 AM, Dick Visser 
> > wrote:
> > 
> > 
> > 
> > 
> > 
> > Hii
> > 
> > Hacking ansible to make it work with its native uri module may
> > work, but it will likely make the hack go under the radar.
> > 
> > 
> > Since it is already a security lowering snowflake, IMHO it is good
> > to make this explicit by having it done in a custom shell/command.
> > It is simple, easy, and makes it very clear what is going on for
> > this specific device.
> > 
> > 
> > 
> > 
> > On Thu, 15 Aug 2024 at 23:31, Garri Djavadyan
> >  wrote:
> > > Hi Walter,
> > > 
> > > > Your system may not allow older TLS connections.
> > > 
> > > Exactly, and this is why I currently have to use a custom
> > > weakened openssl.cnf by the curl-based Ansible playbook. However,
> > > the environment variable OPENSSL_CONF, referring to the custom
> > > OpenSSL config, is ignored when I use "ansible.builtin.uri".
> > > Actually, "ansible.builtin.uri" even ignores by OpenSSL config
> > > located in the default path /etc/ssl/openssl.cnf on my Debian
> > > 12.6 system:
> > > 
> > > -BEGIN SHELL-
> > > $ cat /etc/ssl/openssl.cnf
> > > openssl_conf = openssl_init
> > > 
> > > [openssl_init]
> > > ssl_conf = ssl_sect
> > > 
> > > [ssl_sect]
> > > system_default = system_default_sect
> > > 
> > > [system_default_sect]
> > > MinProtocol = TLSv1
> > > CipherString = DEFAULT@SECLEVEL=0
> > > Options = UnsafeLegacyRenegotiation
> > > 
> > > 
> > > $ ansible-playbook -vvv test.yml
> > > ...
> > > "msg": "Status code was -1 and not [200]: Request failed:
> > >  > > handshake failure (_ssl.c:1000)>",
> > > ...
> > > -END SHELL-
> > > 
> > > 
> > > Thank you.
> > > 
> > > Regards,
> > > Garri
> > > 
> > > 
> > > 
> > > On Thursday, August 15, 2024 at 1:15:22 PM UTC+2 Rowe, Walter P.
> > > (Fed) wrote:
> > > > Check your system settings. Your system may not allow older TLS
> > > > connections. TLS 1.0 is compromised and therefore no longer
> > > > allowed by many systems.
> > > > 
> > > > What platform is your control host?
> > > > 
> > > > Walter
> > > > --
> > > > Walter Rowe, Division Chief
> > > > Infrastructure Services Division
> > > > Mobile: 202.355.4123 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > > On Aug 15, 2024, at 5:00 AM, Garri Djavadyan
> > > > >  wrote:
> > > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > > Hi Steve,
> > > > > 
> > > > > > Did you try with SECLEVEL=0 ?
> > > > > 
> > > > > Yes, I did. However, the result is the same: Ansible
> > > > > controller is not happy with the bare TLS 1.0 reply from the
> > > > > legacy box:
> > > > > 
> > > > > "msg": "Status code was -1 and not [200]: Request failed:
> > > > >  > > > > protocol (_ssl.c:1000)>"
> > > > > 
> > > > > 
> > > > > - name: Query legacy boxes
> > > > >   hosts: legacyboxes
> > > > >   gather_facts: false
> > > > >   connection: local
> > > > >   tasks:
> > > > >     - name: GET the home page
> > > > >       ansible.builtin.uri:
> > > > >         url: https://{{ ansible_host }}
> > > > >         ciphers:
> > > > >           - 'DEFAULT@SECLEVEL=0'
> > > > >           
> > > > > 
> > > > > Again, ciphers-wise, the setup is fine, but I do not think it
> > > > > is possible to enforce the minimum TLS 

Re: [ansible-project] Ansible loop issue

2024-08-16 Thread Todd Lewis
I'm inclined to believe someone is confused by the two |hostname:| 
parameters, and would need to see some job log evidence supporting the 
claim that "the sub[stitution] is being made for |name:| but not for 
|hostname:|." In any case, something from the job log would/should be 
informative.


I've found in situations like this it's helpful to change to module to 
|ansible.builtin.debug:| immediately followed by |msg: ||. You'd then 
need to play with indentation a little to make it informative.


On 8/16/24 1:52 PM, HBach wrote:

Hi, Community,

I am passing in a list, 'vmware_hosts', to the loop in the following 
task in order to substitute values for the name: and hostname: 
parameters.  I have found only the sub is being made for name: but not 
for hostname:.


- name: Set powerstate of a virtual machine to poweron
  community.vmware.vmware_guest:
    hostname: "{{ vc_host_id }}"
    username: "{{ username }}"
    password: "{{ survey_password }}"
name: "{{ item }}"
    customization:
      existing_vm: true
      dns_servers:
      - "{{ dns_ns1 }}"
      - "{{ dns_ns2 }}"
hostname: "{{ item }}"
    state: poweredon
    wait_for_ip_address: true
  loop: "{{ vmware_hosts }}"
  register: vm_state
  delegate_to: localhost

For each iteration of the loop, i.e. a different host, I need these 
two parameters to hold the same value.


What am I missing here?

Thanks!
--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/832cd4cf-942a-48c6-b73c-25a7f48a018an%40googlegroups.com 
.


--
Todd

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/339ab08c-faf9-42ac-9a96-6e735fcedfd2%40gmail.com.


Re: [ansible-project] Ansible is giving below error

2024-08-16 Thread Dick Visser
And your question is?

On Fri, 16 Aug 2024 at 12:42, Aamir Mansoori  wrote:

> Hello All,
>
> I am getting below error while running the ansible consul1 -m ping on my
> debian controller and host.
>
> consul1 | UNREACHABLE! => {
> "changed": false,
> "msg": "Failed to create temporary directory.In some cases, you may
> have been able to authenticate and did not have permissions on the target
> directory. Consider changing the remote tmp path in ansible.cfg to a path
> rooted in \"/tmp\", for more error information use -vvv. Failed command
> was: ( umask 77 && mkdir -p \"` echo /home/ansible/.ansible/tmp `\"&& mkdir
> \"` echo
> /home/ansible/.ansible/tmp/ansible-tmp-1723792189.0846684-1866486-106472010969667
> `\" && echo ansible-tmp-1723792189.0846684-1866486-106472010969667=\"` echo
> /home/ansible/.ansible/tmp/ansible-tmp-1723792189.0846684-1866486-106472010969667
> `\" ), exited with result 127",
> "unreachable": true
> }
>
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/d798deed-075a-4f99-ba0f-bdfdd8797383n%40googlegroups.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAF8BbLaZijTAJrATQzFPH5tFCn8ZP7hQuRMRCnPwsmSL9sfxYg%40mail.gmail.com.


Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-16 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
If the kernel / OS won't allow lowering the TLS then a custom openssl.conf 
likely won't either. You can't override the kernel / OS to lower security.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Aug 16, 2024, at 5:23 AM, Dick Visser  wrote:

Hii

Hacking ansible to make it work with its native uri module may work, but it 
will likely make the hack go under the radar.
Since it is already a security lowering snowflake, IMHO it is good to make this 
explicit by having it done in a custom shell/command.
It is simple, easy, and makes it very clear what is going on for this specific 
device.


On Thu, 15 Aug 2024 at 23:31, Garri Djavadyan 
mailto:[email protected]>> wrote:
Hi Walter,

> Your system may not allow older TLS connections.

Exactly, and this is why I currently have to use a custom weakened openssl.cnf 
by the curl-based Ansible playbook. However, the environment variable 
OPENSSL_CONF, referring to the custom OpenSSL config, is ignored when I use 
"ansible.builtin.uri". Actually, "ansible.builtin.uri" even ignores by OpenSSL 
config located in the default path /etc/ssl/openssl.cnf on my Debian 12.6 
system:

-BEGIN SHELL-
$ cat /etc/ssl/openssl.cnf
openssl_conf = openssl_init

[openssl_init]
ssl_conf = ssl_sect

[ssl_sect]
system_default = system_default_sect

[system_default_sect]
MinProtocol = TLSv1
CipherString = DEFAULT@SECLEVEL=0
Options = UnsafeLegacyRenegotiation


$ ansible-playbook -vvv test.yml
...
"msg": "Status code was -1 and not [200]: Request failed: ",
...
-END SHELL-


Thank you.

Regards,
Garri

On Thursday, August 15, 2024 at 1:15:22 PM UTC+2 Rowe, Walter P. (Fed) wrote:
Check your system settings. Your system may not allow older TLS connections. 
TLS 1.0 is compromised and therefore no longer allowed by many systems.

What platform is your control host?

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Aug 15, 2024, at 5:00 AM, Garri Djavadyan  wrote:

Hi Steve,

> Did you try with SECLEVEL=0 ?

Yes, I did. However, the result is the same: Ansible controller is not happy 
with the bare TLS 1.0 reply from the legacy box:

"msg": "Status code was -1 and not [200]: Request failed: "


- name: Query legacy boxes
  hosts: legacyboxes
  gather_facts: false
  connection: local
  tasks:
- name: GET the home page
  ansible.builtin.uri:
url: https://{{ ansible_host }}
ciphers:
  - 'DEFAULT@SECLEVEL=0'


Again, ciphers-wise, the setup is fine, but I do not think it is possible to 
enforce the minimum TLS protocol version with the cipher string.

Thank you.

Regards,
Garri

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/85e58522-271e-45aa-832a-8a2a7c6b5a38n%40googlegroups.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 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fe2f9e80-a54e-4ffc-87f1-bdfe8788c858n%40googlegroups.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 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAF8BbLaK%3DxwBsph-SMrvdKRBSUCT4SKvnAYxwUk%3Dhio9orKJNg%40mail.gmail.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/47DF4767-7E7B-4494-A0E4-C98B54D95CC7%40nist.gov.


Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-16 Thread Dick Visser
Hii

Hacking ansible to make it work with its native uri module may work, but it
will likely make the hack go under the radar.
Since it is already a security lowering snowflake, IMHO it is good to make
this explicit by having it done in a custom shell/command.
It is simple, easy, and makes it very clear what is going on for this
specific device.


On Thu, 15 Aug 2024 at 23:31, Garri Djavadyan  wrote:

> Hi Walter,
>
> > Your system may not allow older TLS connections.
>
> Exactly, and this is why I currently have to use a custom weakened
> openssl.cnf by the curl-based Ansible playbook. However, the environment
> variable OPENSSL_CONF, referring to the custom OpenSSL config, is ignored
> when I use "ansible.builtin.uri". Actually, "ansible.builtin.uri" even
> ignores by OpenSSL config located in the default path /etc/ssl/openssl.cnf
> on my Debian 12.6 system:
>
> -BEGIN SHELL-
> $ cat /etc/ssl/openssl.cnf
> openssl_conf = openssl_init
>
> [openssl_init]
> ssl_conf = ssl_sect
>
> [ssl_sect]
> system_default = system_default_sect
>
> [system_default_sect]
> MinProtocol = TLSv1
> CipherString = DEFAULT@SECLEVEL=0
> Options = UnsafeLegacyRenegotiation
>
>
> $ ansible-playbook -vvv test.yml
> ...
> "msg": "Status code was -1 and not [200]: Request failed:  [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure
> (_ssl.c:1000)>",
> ...
> -END SHELL-
>
>
> Thank you.
>
> Regards,
> Garri
>
> On Thursday, August 15, 2024 at 1:15:22 PM UTC+2 Rowe, Walter P. (Fed)
> wrote:
>
>> Check your system settings. Your system may not allow older TLS
>> connections. TLS 1.0 is compromised and therefore no longer allowed by many
>> systems.
>>
>> What platform is your control host?
>>
>> Walter
>> --
>> Walter Rowe, Division Chief
>> Infrastructure Services Division
>> Mobile: 202.355.4123 <(202)%20355-4123>
>>
>> On Aug 15, 2024, at 5:00 AM, Garri Djavadyan  wrote:
>>
>> Hi Steve,
>>
>> > Did you try with SECLEVEL=0 ?
>>
>> Yes, I did. However, the result is the same: Ansible controller is not
>> happy with the bare TLS 1.0 reply from the legacy box:
>>
>> "msg": "Status code was -1 and not [200]: Request failed: > [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1000)>"
>>
>>
>> - name: Query legacy boxes
>>   hosts: legacyboxes
>>   gather_facts: false
>>   connection: local
>>   tasks:
>> - name: GET the home page
>>   ansible.builtin.uri:
>> url: https://{{ ansible_host }}
>> ciphers:
>>   - 'DEFAULT@SECLEVEL=0'
>>
>>
>> Again, ciphers-wise, the setup is fine, but I do not think it is possible
>> to enforce the minimum TLS protocol version with the cipher string.
>>
>> Thank you.
>>
>> Regards,
>> Garri
>>
>> --
>> 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 [email protected].
>>
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/85e58522-271e-45aa-832a-8a2a7c6b5a38n%40googlegroups.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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/fe2f9e80-a54e-4ffc-87f1-bdfe8788c858n%40googlegroups.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAF8BbLaK%3DxwBsph-SMrvdKRBSUCT4SKvnAYxwUk%3Dhio9orKJNg%40mail.gmail.com.


Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-15 Thread Garri Djavadyan
Hi Walter,

> Your system may not allow older TLS connections.

Exactly, and this is why I currently have to use a custom weakened 
openssl.cnf by the curl-based Ansible playbook. However, the environment 
variable OPENSSL_CONF, referring to the custom OpenSSL config, is ignored 
when I use "ansible.builtin.uri". Actually, "ansible.builtin.uri" even 
ignores by OpenSSL config located in the default path /etc/ssl/openssl.cnf 
on my Debian 12.6 system:

-BEGIN SHELL-
$ cat /etc/ssl/openssl.cnf
openssl_conf = openssl_init

[openssl_init]
ssl_conf = ssl_sect

[ssl_sect]
system_default = system_default_sect

[system_default_sect]
MinProtocol = TLSv1
CipherString = DEFAULT@SECLEVEL=0
Options = UnsafeLegacyRenegotiation


$ ansible-playbook -vvv test.yml
...
"msg": "Status code was -1 and not [200]: Request failed: ",
...
-END SHELL-


Thank you.

Regards,
Garri

On Thursday, August 15, 2024 at 1:15:22 PM UTC+2 Rowe, Walter P. (Fed) 
wrote:

> Check your system settings. Your system may not allow older TLS 
> connections. TLS 1.0 is compromised and therefore no longer allowed by many 
> systems. 
>
> What platform is your control host?
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services Division
> Mobile: 202.355.4123 <(202)%20355-4123> 
>
> On Aug 15, 2024, at 5:00 AM, Garri Djavadyan  wrote:
>
> Hi Steve,
>
> > Did you try with SECLEVEL=0 ?
>
> Yes, I did. However, the result is the same: Ansible controller is not 
> happy with the bare TLS 1.0 reply from the legacy box:
>
> "msg": "Status code was -1 and not [200]: Request failed:  [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1000)>"
>
>
> - name: Query legacy boxes
>   hosts: legacyboxes
>   gather_facts: false
>   connection: local
>   tasks:
> - name: GET the home page
>   ansible.builtin.uri:
> url: https://{{ ansible_host }}
> ciphers:
>   - 'DEFAULT@SECLEVEL=0'
>   
>
> Again, ciphers-wise, the setup is fine, but I do not think it is possible 
> to enforce the minimum TLS protocol version with the cipher string.
>
> Thank you.
>
> Regards,
> Garri 
>
> -- 
> 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 [email protected].
>
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/85e58522-271e-45aa-832a-8a2a7c6b5a38n%40googlegroups.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fe2f9e80-a54e-4ffc-87f1-bdfe8788c858n%40googlegroups.com.


Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-15 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
Check your system settings. Your system may not allow older TLS connections. 
TLS 1.0 is compromised and therefore no longer allowed by many systems.

What platform is your control host?

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Aug 15, 2024, at 5:00 AM, Garri Djavadyan  wrote:

Hi Steve,

> Did you try with SECLEVEL=0 ?

Yes, I did. However, the result is the same: Ansible controller is not happy 
with the bare TLS 1.0 reply from the legacy box:

"msg": "Status code was -1 and not [200]: Request failed: "


- name: Query legacy boxes
  hosts: legacyboxes
  gather_facts: false
  connection: local
  tasks:
- name: GET the home page
  ansible.builtin.uri:
url: https://{{ ansible_host }}
ciphers:
  - 'DEFAULT@SECLEVEL=0'


Again, ciphers-wise, the setup is fine, but I do not think it is possible to 
enforce the minimum TLS protocol version with the cipher string.

Thank you.

Regards,
Garri

--
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 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/85e58522-271e-45aa-832a-8a2a7c6b5a38n%40googlegroups.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/79414717-CC5B-4312-A749-ECB405BE4E2E%40nist.gov.


Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-15 Thread Garri Djavadyan
Hi Steve,

> Did you try with SECLEVEL=0 ?

Yes, I did. However, the result is the same: Ansible controller is not 
happy with the bare TLS 1.0 reply from the legacy box:

"msg": "Status code was -1 and not [200]: Request failed: "


- name: Query legacy boxes
  hosts: legacyboxes
  gather_facts: false
  connection: local
  tasks:
- name: GET the home page
  ansible.builtin.uri:
url: https://{{ ansible_host }}
ciphers:
  - 'DEFAULT@SECLEVEL=0'
  

Again, ciphers-wise, the setup is fine, but I do not think it is possible 
to enforce the minimum TLS protocol version with the cipher string.

Thank you.

Regards,
Garri

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/85e58522-271e-45aa-832a-8a2a7c6b5a38n%40googlegroups.com.


Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-15 Thread Stephen Maher
Hi,

Did you try with SECLEVEL=0 ?

Level 0: No restrictions. Everything is allowed.

Regards



> On 14 Aug 2024, at 16:15, Garri Djavadyan  wrote:
> 
> SECLEVEL=2

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2AD2A527-63E4-475A-9E32-258100D35A45%40gmail.com.


Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-14 Thread Garri Djavadyan
Hi Steve,

Thank you for your comments.

> Have you seen that the uri module has a ciphers verb as per below.

Yes, I checked it before but did not play with it as it only allows to set 
ciphers. Anyway, I tried it and see that the handshake moved further. 
Namely, once I allow TLS 1.0 compatible ciphers with the string 
'DEFAULT@SECLEVEL=2' for the 'uri' module, Ansible controller starts 
including the TLS 1.0 compatible cipher suite TLS_RSA_WITH_AES_256_CBC_SHA 
(0x0035) in the Client Hello. As a result, the legacy side now replies with 
Server Hello (not TLS Alert as before). However, the Ansible controller now 
initiates the TLS Alert as it does not see TLS version extensions in the 
reply:

Transport Layer Security
TLSv1 Record Layer: Alert (Level: Fatal, Description: Protocol Version)
Content Type: Alert (21)
Version: TLS 1.2 (0x0303)
Length: 2
Alert Message
Level: Fatal (2)
Description: Protocol Version (70)

This is Ansible's error message respectively:

"msg": "Status code was -1 and not [200]: Request failed: "


To summarise, what I see is that 'DEFAULT@SECLEVEL=2' enables TLS 1.0 
compatible cipher suites but does not allow to use the legacy protocol 
itself.

Thank you.

Regards,
Garri

On Wednesday, August 14, 2024 at 3:03:22 PM UTC+2 Stephen Maher wrote:

> Hi Garri,
>
> Have you seen that the uri module has a ciphers verb as per below.
>
>
> https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/uri.py
> https://github.com/ansible/ansible/pull/78650
>
> - name: Provide SSL/TLS ciphers as a list
>   uri:
> url: https://example.org
> ciphers:
>   - '@SECLEVEL=2'
>
>
> Regards
>
> Steve Maher
>
> On 13 Aug 2024, at 11:44, Garri Djavadyan  wrote:
>
> SECLEVEL
>
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/706db547-c26a-47f7-bf5a-8b1af0c47d91n%40googlegroups.com.


Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-14 Thread Stephen Maher
Hi Garri,

Have you seen that the uri module has a ciphers verb as per below.


https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/uri.py 

https://github.com/ansible/ansible/pull/78650

- name: Provide SSL/TLS ciphers as a list
  uri:
url: https://example.org
ciphers:
  - '@SECLEVEL=2'


Regards

Steve Maher

> On 13 Aug 2024, at 11:44, Garri Djavadyan  wrote:
> 
> SECLEVEL

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/669345F2-CAEF-46DD-BF6A-CCBDE0E31512%40gmail.com.


Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-13 Thread Garri Djavadyan
Hi Stephen and Ansible People,

I am sorry, I am afraid my feedback was not correct enough.

The trick with the custom OpenSSL config file defined as an environment 
variable in the Ansible playbook helped me achieve the goal: to access the 
legacy devices with Ansible. However, to do so, I still used "curl" 
executed in "ansible.builtin.shell". Initially, the default OpenSSL config 
did not work for some my devices using "curl" either as legacy TLS 
renegotiation (UnsafeLegacyRenegotiation) is disabled by default.

Therefore, I assumed, that the very same approach should work similarly for 
"ansible.builtin.uri". However, today, once I started rewriting the 
playbook, to replace "curl" with "ansible.builtin.uri", I learned that it 
is not the case. In fact, the handshake fails:

"msg": "Status code was -1 and not [200]: Request failed: ",
"redirected": false,
"status": -1,


Below is my test playbook:

-BEGIN PLAYBOOK-
- name: Query legacy boxes
  hosts: legacyboxes
  gather_facts: false
  connection: local
  environment:
OPENSSL_CONF: /etc/ssl/openssl-unsafe.cnf
  tasks:
- name: GET the home page
  ansible.builtin.uri:
url: https://{{ ansible_host }}
-END PLAYBOOK-


And my custom OpenSSL config (/etc/ssl/openssl-unsafe.cnf) is defined as:

-BEGIN OPENSSL_CONF-
openssl_conf = openssl_init

[openssl_init]
ssl_conf = ssl_sect

[ssl_sect]
system_default = system_default_sect

[system_default_sect]
MinProtocol = TLSv1
CipherString = DEFAULT@SECLEVEL=0
Options = UnsafeLegacyRenegotiation
-END OPENSSL_CONF-


In the packet dumps I see that "ansible.builtin.uri" still announces only 
TLS versions 1.2 and 1.3:

-BEGIN PACKET DUMP-
Extension: supported_versions (len=5) TLS 1.3, TLS 1.2
Type: supported_versions (43)
Length: 5
Supported Versions length: 4
Supported Version: TLS 1.3 (0x0304)
Supported Version: TLS 1.2 (0x0303)
-END PACKET DUMP-


While "curl" expectedly sends the minimal TLS version 1.0:

-BEGIN PACKET DUMP-
Extension: supported_versions (len=9) TLS 1.3, TLS 1.2, TLS 1.1, TLS 1.0
Type: supported_versions (43)
Length: 9
Supported Versions length: 8
Supported Version: TLS 1.3 (0x0304)
Supported Version: TLS 1.2 (0x0303)
Supported Version: TLS 1.1 (0x0302)
Supported Version: TLS 1.0 (0x0301)
-END PACKET DUMP-


I am really sorry for the caused confusion.

Thank you.

Garri

On Wednesday, August 7, 2024 at 1:48:01 PM UTC+2 Stephen Maher wrote:

> Good feed back and thanks Garri (and not Caroline, apologies!) - hopefully 
> someone will find this answer more easily in the future
>
> Regards
>
>
>
> On 7 Aug 2024, at 12:24, Garri Djavadyan  wrote:
>
> Hi Stephan,
>
> Thank you for your answer!
>
> It took a few weeks for my question to be approved actually: I did not 
> even expect it would be published eventually. :)
>
> Yes, the method you mentioned works pretty well as I had to go with that 
> approach 2 weeks ago.
>
> Sorry I could not mention the solution earlier as my initial question (Jul 
> 24) came only today (Aug 7).
>
> Again, thank you.
>
> Regards,
> Garri
>
> On Wednesday, August 7, 2024 at 12:54:48 PM UTC+2 Stephen Maher wrote:
>
>> Hi Caroline,
>>
>> In the past where I have had issues here I have created a custom SSL 
>> config, I think many forget that its possible to customise the SSL config 
>> in this way and this can solve some of the issues where the SSL config in 
>> controller or execution environment is not quite right for your outcome.
>>
>> ie.
>>
>> - name: Get stuff
>>   environment:
>> OPENSSL_CONF: /path/to/your/custom/openssl.cnf
>>   ansible.builtin.uri:
>> ….
>>   
>> And within the SSL config set MinProtocol & CipherString or update in 
>> Protocol.
>>
>> I should think this will help.
>>
>> Regards
>>
>> Steve Maher
>>
>>
>> On 23 Jul 2024, at 23:19, Garri Djavadyan  wrote:
>>
>> ansible.builtin.uri 
>>
>>
>>
> -- 
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/8111b62b-fb5f-468e-8c8b-f6765b7cfc71n%40googlegroups.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/9840db4c-6df4-461e-ac13-462d24ac16adn%40googlegroups.com.


Re: [ansible-project] Re: Unable to upload zip.bin file using uri module

2024-08-07 Thread Matt Martz
That is not a correct assessment of the issue. The server software handling
the upload is incapable of utilizing the Content-Transfer-Encoding of
multipart form data, and the python standard lib code is only capable of
sending binary data with a base64 (or similar) encoding.

It is possible, but may be dependent on the server software that is
receiving the data.

On Wed, Aug 7, 2024 at 6:09 AM R Batchen  wrote:

> well i got my anser in ansible github - it is impossible at a moment to
> post bin files using uri
> thnks
>
> ב-יום שלישי, 16 ביולי 2024 בשעה 12:37:51 UTC+3, R Batchen כתב/ה:
>
>> also the correct file type is seen as "data" when uploaded and from uri
>> it is uploaded as ASCII
>>
>> ansible==2.10.5
>> ansible-base==2.10.17
>> ב-יום שני, 15 ביולי 2024 בשעה 16:21:10 UTC+3, R Batchen כתב/ה:
>>
>>> Im tring to translate a play i have that is using curl to use uri and
>>> nothing works for me
>>> this is the what works for now:
>>>
>>>   # - name: install  via shell
>>>   #   shell: "curl -k --fail --connect-timeout 1 --max-time 1200 -X
>>> \"POST\" \"https://127.0.0.1:8080/v0/upload\"; -H \"Authorization:
>>> Bearer {{ login.json.access_token }}\" -H \"Content-Type:
>>> multipart/form-data\" -F \"in_file=@/home/user/bundles/{{ item.key
>>> }}_docker.zip.bin\""
>>>   #   loop: "{{ template|dict2items }}"
>>>
>>> now i have translated this to uri:
>>>
>>>   - name: install
>>> become: yes
>>> uri:
>>>   url: "https://127.0.0.1:8080/v0/upload";
>>>   headers:
>>> Authorization: "Bearer {{ login.json.access_token }}"
>>> Accept: application/json
>>> Content-Type: multipart/form-data
>>>   validate_certs: no
>>>   body_format: form-multipart
>>>   method: POST
>>>   timeout: 1200
>>>   remote_src: yes
>>>   body:
>>> in_file:
>>>filename: "/home/user/bundles/{{ item.key }}_docker.zip.bin"
>>> mime_type: application/octet-stream
>>> loop: "{{ template | dict2items }}"
>>>
>>> because this file is encrypted for some reason the uri module doesnt
>>> upload it correctly
>>> in my server that the file is posted to , need to run some decryped
>>> script
>>> and the file using the uri module is uploaded as not binary file if i
>>> open it - it looks like a certificate file inside and also the file size is
>>> bigger
>>>
>>> if i uploads it using curl and open the file i can see the file is
>>> binary file and the file size is smaller
>>> what is hapening? why is the uri module changing the file?
>>>
>>> please help?
>>>
>> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/e2f1ea94-d743-4df2-b30b-ccf9ce8b90c7n%40googlegroups.com
> 
> .
>


-- 
Matt Martz
@sivel
sivel.net

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAD8N0v-v8i9nfpro8%3DsN-1sqDC19xH26%2Btb%3Dm95%3Djns7V5aXmA%40mail.gmail.com.


Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-07 Thread Stephen Maher
Good feed back and thanks Garri (and not Caroline, apologies!) - hopefully 
someone will find this answer more easily in the future

Regards



> On 7 Aug 2024, at 12:24, Garri Djavadyan  wrote:
> 
> Hi Stephan,
> 
> Thank you for your answer!
> 
> It took a few weeks for my question to be approved actually: I did not even 
> expect it would be published eventually. :)
> 
> Yes, the method you mentioned works pretty well as I had to go with that 
> approach 2 weeks ago.
> 
> Sorry I could not mention the solution earlier as my initial question (Jul 
> 24) came only today (Aug 7).
> 
> Again, thank you.
> 
> Regards,
> Garri
> 
> On Wednesday, August 7, 2024 at 12:54:48 PM UTC+2 Stephen Maher wrote:
> Hi Caroline,
> 
> In the past where I have had issues here I have created a custom SSL config, 
> I think many forget that its possible to customise the SSL config in this way 
> and this can solve some of the issues where the SSL config in controller or 
> execution environment is not quite right for your outcome.
> 
> ie.
> 
> - name: Get stuff
>   environment:
> OPENSSL_CONF: /path/to/your/custom/openssl.cnf
>   ansible.builtin.uri:
> ….
>   
> And within the SSL config set MinProtocol & CipherString or update in 
> Protocol.
> 
> I should think this will help.
> 
> Regards
> 
> Steve Maher
> 
> 
>> On 23 Jul 2024, at 23:19, Garri Djavadyan > > wrote:
>> 
>> ansible.builtin.uri 
> 
> 
> -- 
> 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 [email protected] 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/8111b62b-fb5f-468e-8c8b-f6765b7cfc71n%40googlegroups.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/B3B8F005-6A9F-4D48-AA1C-AD567C196AA2%40gmail.com.


Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-07 Thread Garri Djavadyan
Hi Stephan,

Thank you for your answer!

It took a few weeks for my question to be approved actually: I did not even 
expect it would be published eventually. :)

Yes, the method you mentioned works pretty well as I had to go with that 
approach 2 weeks ago.

Sorry I could not mention the solution earlier as my initial question (Jul 
24) came only today (Aug 7).

Again, thank you.

Regards,
Garri

On Wednesday, August 7, 2024 at 12:54:48 PM UTC+2 Stephen Maher wrote:

> Hi Caroline,
>
> In the past where I have had issues here I have created a custom SSL 
> config, I think many forget that its possible to customise the SSL config 
> in this way and this can solve some of the issues where the SSL config in 
> controller or execution environment is not quite right for your outcome.
>
> ie.
>
> - name: Get stuff
>   environment:
> OPENSSL_CONF: /path/to/your/custom/openssl.cnf
>   ansible.builtin.uri:
> ….
>   
> And within the SSL config set MinProtocol & CipherString or update in 
> Protocol.
>
> I should think this will help.
>
> Regards
>
> Steve Maher
>
>
> On 23 Jul 2024, at 23:19, Garri Djavadyan  wrote:
>
> ansible.builtin.uri 
>
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/8111b62b-fb5f-468e-8c8b-f6765b7cfc71n%40googlegroups.com.


Re: [ansible-project] Force ansible.builtin.uri to use minimum TLS version

2024-08-07 Thread Stephen Maher
Hi Caroline,

In the past where I have had issues here I have created a custom SSL config, I 
think many forget that its possible to customise the SSL config in this way and 
this can solve some of the issues where the SSL config in controller or 
execution environment is not quite right for your outcome.

ie.

- name: Get stuff
  environment:
OPENSSL_CONF: /path/to/your/custom/openssl.cnf
  ansible.builtin.uri:
….
  
And within the SSL config set MinProtocol & CipherString or update in Protocol.

I should think this will help.

Regards

Steve Maher


> On 23 Jul 2024, at 23:19, Garri Djavadyan  wrote:
> 
> ansible.builtin.uri 

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/0333F06D-5BBE-48D0-8226-2B980366CC3E%40gmail.com.


Re: [ansible-project] creating RSA key with openssh_keypair

2024-08-03 Thread Dick Visser
On Thu, 1 Aug 2024 at 19:21, Veera  wrote:

>
>
> Yes  ,  We need a RSA format PEM key  which is compatible with the
> application .
>  Whenever a OPENSSH PRIVATE  Key generated with the playbook is used for
> authentication ,  login to the application  is working but its not
> functioning 100% as expected .
> When a RSA format PEM or id_rsa key ( ssh-keygen -t rsa -b 2048) is used
> then login and functioning of the application is working fine.  (vendor
> recommended RSA format SSH key)
>

Add the following parameters to your task:

backend: cryptography
private_key_format: pkcs1

Looking at the docs
,
this means that your application depends on OpenSSH < 7.8, because only
those versions created PKCS1 private key files (the ones with "BEGIN
RSA...").
See https://superuser.com/questions/1720991/ for an interesting read on
some historical background and rationale.
After reading that you may want to ask questions to your vendor, for
example why their application insists on a legacy, less secure format
(although the latter only applies to encrypted keys, which you don't seem
to be generating).
If it is a key for ssh, then they might also be using specific fields from
the ASN.1 structure. This is possible, but then it's not just an ssh key
anymore.

Dick

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAF8BbLZj2dSZCdqaPh3Q837eaLWZRoMz1AsS46KENZ6-TZD3QQ%40mail.gmail.com.


Re: [ansible-project] creating RSA key with openssh_keypair

2024-08-02 Thread Todd Lewis
In what way is it "not functioning 100% as expected"?

On Thursday, August 1, 2024 at 1:21:26 PM UTC-4 Veera wrote:

>
>
> Yes  ,  We need a RSA format PEM key  which is compatible with the 
> application . 
>  Whenever a OPENSSH PRIVATE  Key generated with the playbook is used for 
> authentication ,  login to the application  is working but its not  
> functioning 100% as expected . 
> When a RSA format PEM or id_rsa key ( ssh-keygen -t rsa -b 2048) is used  
> then login and functioning of the application is working fine.  (vendor 
> recommended RSA format SSH key)
>
>
>   
> On Thursday, August 1, 2024 at 7:51:33 PM UTC+5:30 Felix Fontein wrote:
>
>> Hi, 
>>
>> > However the public-key is showing the caption as ssh-rsa .. and the 
>> > private key is displaying the label as "-BEGIN OPENSSH PRIVATE 
>> > KEY- and -END OPENSSH PRIVATE KEY-" 
>> > 
>> > I am looking to create an rsa key-pairs with 2048b , something we 
>> > used to create with the command ssh-keygen -t rsa -b 2048 
>> > The private key must begin with "-BEGIN RSA PRIVATE KEY-" and 
>> > ends with "-END RSA PRIVATE KEY-" 
>>
>> Could you please elaborate why it **must** start with "-BEGIN RSA 
>> PRIVATE KEY-"? Does your SSH version not accept "-BEGIN OPENSSH 
>> PRIVATE KEY-"? 
>>
>> In any case, I would suggest to look at the private_key_format option 
>> of the module. 
>>
>> All the best, 
>> Felix 
>>
>>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/cb401600-0bf4-4c68-880c-e236af377d7dn%40googlegroups.com.


Re: [ansible-project] creating RSA key with openssh_keypair

2024-08-01 Thread Veera


Yes  ,  We need a RSA format PEM key  which is compatible with the 
application . 
 Whenever a OPENSSH PRIVATE  Key generated with the playbook is used for 
authentication ,  login to the application  is working but its not  
functioning 100% as expected . 
When a RSA format PEM or id_rsa key ( ssh-keygen -t rsa -b 2048) is used  
then login and functioning of the application is working fine.  (vendor 
recommended RSA format SSH key)


  
On Thursday, August 1, 2024 at 7:51:33 PM UTC+5:30 Felix Fontein wrote:

> Hi,
>
> > However the public-key is showing the caption as ssh-rsa .. and the
> > private key is displaying the label as "-BEGIN OPENSSH PRIVATE
> > KEY- and -END OPENSSH PRIVATE KEY-"
> > 
> > I am looking to create an rsa key-pairs with 2048b , something we
> > used to create with the command ssh-keygen -t rsa -b 2048
> > The private key must begin with "-BEGIN RSA PRIVATE KEY-" and
> > ends with "-END RSA PRIVATE KEY-"
>
> Could you please elaborate why it **must** start with "-BEGIN RSA
> PRIVATE KEY-"? Does your SSH version not accept "-BEGIN OPENSSH
> PRIVATE KEY-"?
>
> In any case, I would suggest to look at the private_key_format option
> of the module.
>
> All the best,
> Felix
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5d6af433-700c-46c0-865c-68c2b334209cn%40googlegroups.com.


Re: [ansible-project] creating RSA key with openssh_keypair

2024-08-01 Thread 'Felix Fontein' via Ansible Project
Hi,

> However the public-key is showing the caption as ssh-rsa .. and the
> private key is displaying the  label as "-BEGIN OPENSSH PRIVATE
> KEY- and  -END OPENSSH PRIVATE KEY-"
> 
> I am looking  to create an rsa key-pairs with 2048b  ,  something we
> used to create with the command  ssh-keygen -t rsa -b 2048
> The private key must begin with "-BEGIN RSA PRIVATE KEY-" and
>  ends with "-END RSA PRIVATE KEY-"

Could you please elaborate why it **must** start with "-BEGIN RSA
PRIVATE KEY-"? Does your SSH version not accept "-BEGIN OPENSSH
PRIVATE KEY-"?

In any case, I would suggest to look at the private_key_format option
of the module.

All the best,
Felix

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20240801162036.5072b636%40rovaniemi.


Re: [ansible-project] Get role names for multiple plays in the same playbook file

2024-07-31 Thread Brian Coca
If it is just to display at the end of play, you can also use
'set_stats' 
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/set_stats_module.html
And enable stat display in the default callback (others might/might
not display them).


-- 
--
Brian Coca (he/him/they/them)

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7ddmWMEyWKYfTPp8k9QOs%2B22WFRO8fPX%3DCDRZuGGmZbaQ%40mail.gmail.com.


Re: [ansible-project] Get role names for multiple plays in the same playbook file

2024-07-29 Thread Vladimir Botka
On Mon, 29 Jul 2024 22:53:40 -0400
ricardo barbosa  wrote:

> I have a host host01 in the two groups: GROUP01 and
> GROUP03
> 
> --play.yml
> - name: play 1
>   hosts:
> - GROUP01
>   roles:
> - nginx
> - php
> 
> - name: play 2
>   hosts:
> - GROUP02
>   roles:
> - mysql
> 
> - name: play 3
>   hosts:
> - GROUP03
>   roles:
> - linux
>   tasks:
> - debug:
> msg: "{{ ansible_role_names }}"
> 
> ansible-playbook play.yml --limit host01
> --
> 
> So it will run on play 1 and play 3, so I wanted the "ansible_role_names"
> variable to contain the values "nginx", "PHP" and "linux"

Create the audit on your own. For example, create the file

shell> cat audit.yml
- name: Audit
  when: audit | d(false) | bool
  run_once: true
  block:
- set_fact:
hosts_roles: "{{ hosts_roles | d([]) +
 [ansible_play_hosts_all |
  product([ansible_role_names]) |
  community.general.dict] }}"
- meta: end_play

and import it in each play

shell> cat play.yml
- name: Play 1
  hosts: GROUP01
  pre_tasks:
- import_tasks: audit.yml
  roles:
- nginx
- php

- name: Play 2
  hosts: GROUP02
  pre_tasks:
- import_tasks: audit.yml
  roles:
- mysql

- name: Play 3
  hosts: GROUP03
  pre_tasks:
- import_tasks: audit.yml
  roles:
- linux

To display the audit results add one more play to the
playbook

- name: Audit
  hosts: all
  tasks:
- name: Results
  when: audit | d(false) | bool
  run_once: true
  block:
- debug:
var: hosts_roles | to_yaml
- debug:
var: hosts_roles |
 combine(list_merge='append_rp') | to_yaml


The below command

shell> ansible-playbook play.yml -e audit=true --limit host01

gives what you want

  hosts_roles | to_yaml: |-
- host01: [nginx, php]
- host01: [linux]

  hosts_roles | combine(list_merge='append_rp') | to_yaml:
- host01: [nginx, php, linux]


HTH,

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20240730073549.6d9f42df%40gmail.com.


pgpLq9Javyz1c.pgp
Description: OpenPGP digital signature


Re: [ansible-project] ansible_facts['device_links']['ids'] empty for RHEL9 on AWS

2024-07-17 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
Bravo! It is empty on the RHEL9 system and populated on the RHEL8 system.

Now I need to determine why.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Jul 17, 2024, at 2:27 PM, Abhijeet Kasurde  wrote:

What is the content of /dev/disk/by-id on AWS EC2 instance?


-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/A719A892-3A43-4A37-803E-C6965D55FB47%40nist.gov.


Re: [ansible-project] ansible_facts['device_links']['ids'] empty for RHEL9 on AWS

2024-07-17 Thread Abhijeet Kasurde
What is the content of /dev/disk/by-id on AWS EC2 instance?

On Wed, Jul 17, 2024 at 11:21 AM 'Rowe, Walter P. (Fed)' via Ansible
Project  wrote:

> I am querying ansible facts of AWS EC2s to get volume IDs without having
> to use the AWS API. Prior to Red Hat 9 I could use 
> *ansible_device_links['ids'][device
> name]* to get the associated volume ID.
>
>
> *REDHAT 8 *
> "ansible_facts": {
> "ansible_device_links": {
> "ids": {
> "*nvme0n1*": [
> "nvme-Amazon_Elastic_Block_Store_
> *vol0205cf99926f7c3e8*",
>
>   
> "nvme-nvme.1d0f-766f6c3032303563663939393236663763336538-416d617a6f6e20456c617374696320426c6f636b2053746f7265-0001"
> ],
>
> Starting with Red Hat 9 we seem to have lost this info.
>
>
> *REDHAT 9 *
> "ansible_facts": {
> "ansible_device_links": {
> "ids": {},
>
> Is this something unique to my environment or is this something that
> changed with RHEL facts?
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services Division
> Mobile: 202.355.4123
>
>
> *REDHAT 8 *
> {
> "ansible_facts": {
> "ansible_device_links": {
> "ids": {
> "nvme0n1": [
> "nvme-Amazon_Elastic_Block_Store_vol0205cf99926f7c3e8",
>
> "nvme-nvme.1d0f-766f6c3032303563663939393236663763336538-416d617a6f6e20456c617374696320426c6f636b2053746f7265-0001"
> ],
> "nvme0n1p1": [
>
> "nvme-Amazon_Elastic_Block_Store_vol0205cf99926f7c3e8-part1",
>
> "nvme-nvme.1d0f-766f6c3032303563663939393236663763336538-416d617a6f6e20456c617374696320426c6f636b2053746f7265-0001-part1",
>
> "wwn-nvme.1d0f-766f6c3032303563663939393236663763336538-416d617a6f6e20456c617374696320426c6f636b2053746f7265-0001-part1"
> ],
> "nvme0n1p2": [
>
> "nvme-Amazon_Elastic_Block_Store_vol0205cf99926f7c3e8-part2",
>
> "nvme-nvme.1d0f-766f6c3032303563663939393236663763336538-416d617a6f6e20456c617374696320426c6f636b2053746f7265-0001-part2",
>
> "wwn-nvme.1d0f-766f6c3032303563663939393236663763336538-416d617a6f6e20456c617374696320426c6f636b2053746f7265-0001-part2"
> ],
> "nvme1n1": [
> "nvme-Amazon_Elastic_Block_Store_vol0abf628274ab398f2",
>
> "nvme-nvme.1d0f-766f6c3061626636323832373461623339386632-416d617a6f6e20456c617374696320426c6f636b2053746f7265-0001"
> ],
> "nvme2n1": [
> "nvme-Amazon_Elastic_Block_Store_vol0690b9672f6e52240",
>
> "nvme-nvme.1d0f-766f6c3036393062393637326636653532323430-416d617a6f6e20456c617374696320426c6f636b2053746f7265-0001"
> ],
> "nvme3n1": [
> "nvme-Amazon_Elastic_Block_Store_vol08404f1191eb63440",
>
> "nvme-nvme.1d0f-766f6c3038343034663131393165623633343430-416d617a6f6e20456c617374696320426c6f636b2053746f7265-0001"
> ],
> "nvme4n1": [
> "nvme-Amazon_Elastic_Block_Store_vol081f2b191f4e7d7cc",
>
> "nvme-nvme.1d0f-766f6c3038316632623139316634653764376363-416d617a6f6e20456c617374696320426c6f636b2053746f7265-0001"
> ],
> "nvme5n1": [
> "nvme-Amazon_Elastic_Block_Store_vol0b51ac580c17c745e",
>
> "nvme-nvme.1d0f-766f6c3062353161633538306331376337343565-416d617a6f6e20456c617374696320426c6f636b2053746f7265-0001"
> ],
> "nvme6n1": [
> "nvme-Amazon_Elastic_Block_Store_vol07427283fef5d12ad",
>
> "nvme-nvme.1d0f-766f6c3037343237323833666566356431326164-416d617a6f6e20456c617374696320426c6f636b2053746f7265-0001"
> ],
> "nvme7n1": [
> "nvme-Amazon_Elastic_Block_Store_vol07c3177d94a329f70",
>
> "nvme-nvme.1d0f-766f6c303761373764393461333239663730-416d617a6f6e20456c617374696320426c6f636b2053746f7265-0001"
> ]
> },
> "labels": {
> "nvme1n1": [
> "tmp"
> ],
> "nvme2n1": [
> "swap"
> ],
> "nvme3n1": [
> "apps"
> ],
> "nvme4n1": [
> "external"
> ],
> "nvme5n1": [
> "archive"
> ],
> "nvme6n1": [
> "orafra"
> ],
> "nvme7n1": [
> "oradata"
> ]
> },
> "masters": {},
> "uuids": {
> "nvme0n1p2": [
> "c9aa25ee-e65c-4818-9b2f-fa411d89f585"
> ],
> "nvme1n1": [
> "e5d6f42e-45ca-4b3b-8492-46314d453a31"
> ],
> "nvme2n1": [
> 

Re: [ansible-project] Create inventory in a Workflow and then use in subsequent playbooks

2024-07-10 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
Do you need these plays to be in separate playbook? You can put multiple plays 
in a single playbook. Play one can create an inventory group. Play two can run 
agains that group. We use this for some of our tasks where we create new 
machines, create a new inventory group, then run a play on that new group.


##
## play 1: add new machines to an inventory group
##
- name: Add new host to playbook inventory
hosts: localhost
gather_facts: no

tasks:

# add our new host to the inventory for this play
- name: add {{ item | lower }} to group
add_host:
name: "{{ item | lower }}"
group: newvm
loop: "{{ new_vm_names }}"

##
## play 2: customize new machines
##
- name: "Customize Server - Linux - Set Time Zone, Hostname, Join AD"
gather_facts: no
hosts: newvm

Notice that "hosts" in play #2 refers to the "newvm" group created in play #1.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Jul 10, 2024, at 12:19 PM, HBach  wrote:

Thanks, Walter.

We're not using static addresses but dynamic.  If we were, it would be easier.  
I figured out the Ansible fact to grab the IP but this only grabs it for a 
single host.

ansible_facts["azure_vm"]["network_profile"]["network_interfaces"][0]["properties"]["ip_configurations"][0]["private_ip_address"]

I wrote a simple task to loop through the host list provided in the Ansible 
survey to dump the ips to stdout.

  - name: Gather specific Ansible facts
  debug:
msg: "{{ hostvars[item]['ansible_default_ipv4']['address'] }}"
  loop: "{{ linux_hosts }}"

but it looks like it can't find the host(s).
  "msg": "The task includes an option with an undefined variable. The error 
was: \"hostvars['rheltest0709a']\" is undefined.

Thanks!

On Tuesday, July 9, 2024 at 10:00:09 AM UTC-6 Rowe, Walter P. (Fed) wrote:
You need names and corresponding IP addresses for an inventory.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Jul 9, 2024, at 11:52 AM, HBach  wrote:

Hi, community,

I am creating a deployment workflow using the Ansible Automation Platform (AAP) 
and, right now, the workflow is composed of two job templates.  The first job 
template creates the actual vms and the the second job template is used for 
some post-build configuration tasks.  I want to use the inventory generated in 
the first job template for the second job template.

Right now, I am having AAP reach back to itself via the AAP API and create an 
inventory.  I have also used the set_stats module to create an artifact that 
the second job template can see.

- name: Set stats to pass inventory
  ansible.builtin.set_stats:
data:
  target_hosts: "{{ linux_hosts }}"

- name: Get an AAP API Token and store it as new_token
  register: new_token
  ansible.builtin.uri:
  url: "https:///api/v2/tokens/"
  method: POST
  user: admin
  password: "{{ survey_controller_passwd }}"
  validate_certs: false
  force_basic_auth: true
  status_code: 201
  return_content: true

- name: Azure inventory update
  ansible.controller.host:
controller_host: "https:///"
controller_password: "{{ survey_controller_passwd }}"
controller_username: 'admin'
controller_oauthtoken: "{{ new_token.json.token }}"
name: "{{ linux_hosts }}"
inventory: "Azure-test"
state: present
enabled: true

The artifact is created and the new inventory on AAP is updated when job 
template 1 completes.

{
  "target_hosts": [
"rheltest0701c"
  ]
}

But, the second job template fails as it cannot find the host(s).
[WARNING]: Could not match supplied host pattern, ignoring: target_hosts

Any idea, folks?


--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/aa0fcd58-3f55-4c9a-8ea6-2d0e28fa3495n%40googlegroups.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 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fd7b18b7-e4f0-43af-9d79-e3f02ca3b089n%40googlegroups.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 

Re: [ansible-project] Create inventory in a Workflow and then use in subsequent playbooks

2024-07-10 Thread HBach
Thanks, Walter.  

We're not using static addresses but dynamic.  If we were, it would be 
easier.  I figured out the Ansible fact to grab the IP but this only grabs 
it for a single host.

ansible_facts["azure_vm"]["network_profile"]["network_interfaces"][0]["properties"]["ip_configurations"][0]["private_ip_address"]

I wrote a simple task to loop through the host list provided in the Ansible 
survey to dump the ips to stdout.

  - name: Gather specific Ansible facts
  debug:
msg: "{{ hostvars[item]['ansible_default_ipv4']['address'] }}"
  loop: "{{ linux_hosts }}"

but it looks like it can't find the host(s). 
  "msg": "The task includes an option with an undefined variable. The error 
was: \"hostvars['rheltest0709a']\" is undefined.

Thanks!

On Tuesday, July 9, 2024 at 10:00:09 AM UTC-6 Rowe, Walter P. (Fed) wrote:

> You need names and corresponding IP addresses for an inventory.
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services Division
> Mobile: 202.355.4123 <(202)%20355-4123> 
>
> On Jul 9, 2024, at 11:52 AM, HBach  wrote:
>
> Hi, community, 
>
> I am creating a deployment workflow using the Ansible Automation Platform 
> (AAP) and, right now, the workflow is composed of two job templates.  The 
> first job template creates the actual vms and the the second job template 
> is used for some post-build configuration tasks.  I want to use the 
> inventory generated in the first job template for the second job template.  
>
> Right now, I am having AAP reach back to itself via the AAP API and create 
> an inventory.  I have also used the set_stats module to create an artifact 
> that the second job template can see.  
>
> - name: Set stats to pass inventory
>   ansible.builtin.set_stats:
> data:
>   target_hosts: "{{ linux_hosts }}"
>
> - name: Get an AAP API Token and store it as new_token
>   register: new_token
>   ansible.builtin.uri:
>   url: "https:///api/v2/tokens/"
>   method: POST
>   user: admin
>   password: "{{ survey_controller_passwd }}"
>   validate_certs: false
>   force_basic_auth: true
>   status_code: 201
>   return_content: true
>
> - name: Azure inventory update
>   ansible.controller.host:
> controller_host: "https:///"
> controller_password: "{{ survey_controller_passwd }}"
> controller_username: 'admin'
> controller_oauthtoken: "{{ new_token.json.token }}"
> name: "{{ linux_hosts }}"
> inventory: "Azure-test"
> state: present
> enabled: true
>
> The artifact is created and the new inventory on AAP is updated when job 
> template 1 completes.
>
> {
>   "target_hosts": [
> "rheltest0701c"
>   ]
> } 
>
> But, the second job template fails as it cannot find the host(s).
> *[WARNING]: Could not match supplied host pattern, ignoring: target_hosts*
>
> Any idea, folks? 
>
>
> -- 
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/aa0fcd58-3f55-4c9a-8ea6-2d0e28fa3495n%40googlegroups.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fd7b18b7-e4f0-43af-9d79-e3f02ca3b089n%40googlegroups.com.


Re: [ansible-project] Create inventory in a Workflow and then use in subsequent playbooks

2024-07-09 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
You need names and corresponding IP addresses for an inventory.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On Jul 9, 2024, at 11:52 AM, HBach  wrote:

Hi, community,

I am creating a deployment workflow using the Ansible Automation Platform (AAP) 
and, right now, the workflow is composed of two job templates.  The first job 
template creates the actual vms and the the second job template is used for 
some post-build configuration tasks.  I want to use the inventory generated in 
the first job template for the second job template.

Right now, I am having AAP reach back to itself via the AAP API and create an 
inventory.  I have also used the set_stats module to create an artifact that 
the second job template can see.

- name: Set stats to pass inventory
  ansible.builtin.set_stats:
data:
  target_hosts: "{{ linux_hosts }}"

- name: Get an AAP API Token and store it as new_token
  register: new_token
  ansible.builtin.uri:
  url: "https:///api/v2/tokens/"
  method: POST
  user: admin
  password: "{{ survey_controller_passwd }}"
  validate_certs: false
  force_basic_auth: true
  status_code: 201
  return_content: true

- name: Azure inventory update
  ansible.controller.host:
controller_host: "https:///"
controller_password: "{{ survey_controller_passwd }}"
controller_username: 'admin'
controller_oauthtoken: "{{ new_token.json.token }}"
name: "{{ linux_hosts }}"
inventory: "Azure-test"
state: present
enabled: true

The artifact is created and the new inventory on AAP is updated when job 
template 1 completes.

{
  "target_hosts": [
"rheltest0701c"
  ]
}

But, the second job template fails as it cannot find the host(s).
[WARNING]: Could not match supplied host pattern, ignoring: target_hosts

Any idea, folks?


--
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 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/aa0fcd58-3f55-4c9a-8ea6-2d0e28fa3495n%40googlegroups.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/06F426EE-5A5D-420C-81ED-F26E2C8CB606%40nist.gov.


Re: [ansible-project] Have problems with PB make API calls

2024-07-08 Thread Brian Coca
I used to have some playbooks that did the same, with the first task
calling the API and retrieving the token into a registered var, while
subsequent tasks using that var as input for
authentication/authorization:

- get_url: ...
   register: auth_token

- access_api:
   token: auth_token.body/header/etc

-- 
--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7eis6TT7XXNRJUMp5o%2B72Md8S9_0ZFG13HFUEFraVy40Q%40mail.gmail.com.


Re: [ansible-project] build groups based on hosts and host-variables

2024-07-02 Thread [email protected]
thx a lot for the input. i will read and test all the proposals. THX
regards,
andre

Vladimir Botka schrieb am Montag, 1. Juli 2024 um 21:27:41 UTC+2:

> On Mon, 1 Jul 2024 06:17:26 -0700 (PDT)
> "[email protected]"  wrote:
>
> > ... put group-information into each host ... per host to
> > control if a playbook may or may not work on a host
>
> The playbook name is not available to the inventory
> plugins. The below solution provides the inventory plugin
> with the playbook name in the extra variable. The allowed
> hosts are listed in a dictionary in group_vars.
>
> * Create a dictionary with the lists of the allowed hosts
>
> shell> cat inventory/alllinux/01-hosts.yml 
> alllinux:
> hosts:
> test_01:
> test_02:
> test_03:
> vars:
> play_allow:
> default: []
> playbook_01: [test_01, test_02]
> playbook_02: [test_02, test_03]
>
> For example, the below playbook shall run on the hosts
> test_01 and test_02 only
>
> shell> cat playbook_01.yml 
> - name: playbook_01
> hosts: my_hosts
> tasks:
> - debug:
> msg: Start play
>
> * Use the inventory plugin *constructed* and create the
> group *my_hosts*
>
> shell> cat inventory/alllinux/02-constructed.yml 
> plugin: ansible.builtin.constructed
> use_extra_vars: true
> use_vars_plugins: true
> compose:
> my_hosts_allow: play_allow[my_play|d('default')]
> groups:
> my_hosts: inventory_hostname in my_hosts_allow
>
> * Unfortunately, the name of the playbook is not available
> in the inventory plugins. Therefor, you have to provide
> it explicitly. For example, in the extra vars *my_play*
>
> shell> ansible-playbook -i inventory/alllinux -e my_play=playbook_01 
> playbook_01.yml
>
> gives abridged
>
> ok: [test_01] =>
> msg: Start play
> ok: [test_02] => 
> msg: Start play
>
> HTH,
>
> -- 
> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4b762370-2006-4750-95eb-fdec7eba95a0n%40googlegroups.com.


Re: [ansible-project] build groups based on hosts and host-variables

2024-07-01 Thread Vladimir Botka
On Mon, 1 Jul 2024 06:17:26 -0700 (PDT)
"[email protected]"  wrote:

> ... put group-information into each host ... per host to
> control if a playbook may or may not work on a host

The playbook name is not available to the inventory
plugins. The below solution provides the inventory plugin
with the playbook name in the extra variable. The allowed
hosts are listed in a dictionary in group_vars.

* Create a dictionary with the lists of the allowed hosts

shell> cat inventory/alllinux/01-hosts.yml 
alllinux:
  hosts:
test_01:
test_02:
test_03:
  vars:
play_allow:
  default: []
  playbook_01: [test_01, test_02]
  playbook_02: [test_02, test_03]

For example, the below playbook shall run on the hosts
test_01 and test_02 only

shell> cat playbook_01.yml 
- name: playbook_01
  hosts: my_hosts
  tasks:
- debug:
msg: Start play

* Use the inventory plugin *constructed* and create the
  group *my_hosts*

shell> cat inventory/alllinux/02-constructed.yml 
plugin: ansible.builtin.constructed
use_extra_vars: true
use_vars_plugins: true
compose:
  my_hosts_allow: play_allow[my_play|d('default')]
groups:
  my_hosts: inventory_hostname in my_hosts_allow

* Unfortunately, the name of the playbook is not available
  in the inventory plugins. Therefor, you have to provide
  it explicitly. For example, in the extra vars *my_play*

shell> ansible-playbook -i inventory/alllinux -e my_play=playbook_01 
playbook_01.yml

gives abridged

ok: [test_01] =>
  msg: Start play
ok: [test_02] => 
  msg: Start play

HTH,

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20240701212715.68ce7c50%40gmail.com.


pgpeFZSch24wO.pgp
Description: OpenPGP digital signature


Re: [ansible-project] build groups based on hosts and host-variables

2024-07-01 Thread Brian Coca
The problem was posed with setting variables per host in inventory,
you can use the constructed inventory to use those variables to create
groups, the plays can filter only for the groups they are known to
work with or not, i.e  hosts: valid_groups or  hosts:
normalgropus:!invalid_for_this_play.

if you are getting teh variables dynamically, you can do same/similar
with group_by, but then you need 3 plays, 1 to gather the info, 2 to
use the group_by 3 the original play that processes the 'valid
group(s)'
-- 
--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7di%3DPkVEnnefWKAy2XL749JCNK_Jrs2K6sF%3Dt_EGO%2BGeA%40mail.gmail.com.


Re: [ansible-project] build groups based on hosts and host-variables

2024-07-01 Thread Vladimir Botka
Hi!,

On Mon, 1 Jul 2024 10:56:51 -0400
Brian Coca  wrote:

> https://docs.ansible.com/ansible/latest/collections/ansible/builtin/constructed_inventory.html
> ^ use 3rd inventory source that can construct groups and assign group
> vars based on data from previous inventory sources.

The requirement is to: "control if a playbook may or may not
work on a host". How does the inventory plugin know which
playbook is running? The special variable ansible_play_name
is not available in the inventory plugin.

Thank you,

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20240701180542.23ce39e3%40gmail.com.


pgpS0lQrRymv9.pgp
Description: OpenPGP digital signature


Re: [ansible-project] build groups based on hosts and host-variables

2024-07-01 Thread Brian Coca
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/constructed_inventory.html
^ use 3rd inventory source that can construct groups and assign group
vars based on data from previous inventory sources.

-- 
--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7f-rzTARQLSPO-ZhOZyO--PoPcDSF9nVNyk4WvO9yEjAg%40mail.gmail.com.


Re: [ansible-project] Using Vault in microsoft.ad.ldap.yml

2024-06-17 Thread Will McDonald
From:
https://docs.ansible.com/ansible/latest/collections/microsoft/ad/ldap_inventory.html#parameter-username
And:
https://docs.ansible.com/ansible/latest/collections/microsoft/ad/ldap_inventory.html#parameter-password

If you set both:

MICROSOFT_AD_LDAP_USERNAME
MICROSOFT_AD_LDAP_PASSWORD

e.g.:
$ export MICROSOFT_AD_LDAP_USERNAME=read_only_user
$ export MICROSOFT_AD_LDAP_PASSWORD=Hugely_Complicated_Password

Then those should be consumed by the plugin. If your password has
metacharacters, you'll need to figure out the right combination of
quoting/escaping too to ensure they're ingested correctly?

If you read the examples in the plugin docs, they also show some lookups
being used to populate the config, you could potentially tweak that to pull
from an Ansible vault.


On Mon, 17 Jun 2024 at 14:59, 'Caroline Kiel' via Ansible Project <
[email protected]> wrote:

> Hi everyone,
> I searched this list but couldn't find a valid answer.
>
> I want to use the MS plugin microsoft.ad.ldap.yml inside a playbook.
> As long, as I enter the LDAP username and password as clear text in the
> yml, everything runs smooth.
> But, of course, this is not an option for production, so I'm looking for a
> way to store the password in a vault file.
> Unfortunately, I can't get it to work using variables at all.
> There is a hint that one can use environment variables, but I'm really
> struggling.
>
> Does anyone have a hint for me?
> Thank you very much in advance,
> Caroline
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/abf15b06-b028-4c33-a9ec-7a5e70ad5e2en%40googlegroups.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAKtKohTi%3D6ypTV5AtUF0eZsH81O_5ok1fGccpR2DuuyQ6bZN7Q%40mail.gmail.com.


Re: [ansible-project] Failed to connect to a Windows server using Ansible

2024-06-17 Thread denilson hernandez serpa
I already did, 

Even in the parameterization I indicate it to use HTTPS.

I attach an image of how I have ansible

ansible_user: "{{ansible_user}}"
ansible_password: "{{ansible_password}}"
ansible_connection: "winrm"
ansible_port: 5986
ansible_winrm_scheme: https
ansible_winrm_server_cert_validation: ignore
ansible_winrm_transport: ntlm
ansible_python_interpreter: /usr/bin/python3
El miércoles, 20 de marzo de 2024 a la(s) 6:34:35 a.m. UTC-5, Stuart Lowe 
escribió:

> Looks like it’s failing to verify the certificate to create a secure 
> connection.
>
> Assuming it’s a self signed cert you’ll need to ensure it’s trusted from 
> your control host.
>
> could always disable cert verification but wouldn’t recommend it.
>
> Stu
>
>  
>
> *From:* [email protected]  *On 
> Behalf Of *denilson hernandez serpa
> *Sent:* Tuesday, March 19, 2024 9:13 PM
> *To:* Ansible Project 
> *Subject:* [ansible-project] Failed to connect to a Windows server using 
> Ansible
>
>  
>
> You don't often get email from [email protected]. Learn why this is 
> important 
>
>  
>
> *Caution:* This email originated from outside of the organisation. Do not 
> click links or open attachments unless you recognise the sender and know 
> the content is safe 
>
>  
>
> Hello community. 
>
>  
>
> I hope you are doing well.   
>
>  
>
> I'm using Ansible to automate tasks from my windows servers, but it's 
> giving me an error like this.  Does anyone know how I can fix it?
>
>  
>
> fatal: [xxx]: UNREACHABLE! => {
> "changed": false,
> "msg": "basic: HTTPSConnectionPool(host='xx', port=5986): Max 
> retries exceeded with url: /wsman (Caused by 
> SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] 
> certificate verify failed: unable to get local issuer certificate 
> (_ssl.c:1007)')))",
> "unreachable": true
> }
>
> -- 
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/8ee8e25c-94eb-49ed-beaa-98fe954b809en%40googlegroups.com
>  
> 
> .
> ---
>
> *Stuart Lowe* He/Him
> Zen Cloud Engineering - Team Leader
> *Zen Internet*
> Team: 01706 902009
> www.zen.co.uk 
>
> Proud to be a certified B Corporation
>
> This message is private and confidential. If you have received this 
> message in error, please notify us and remove it from your system.
>
> Zen Internet Limited may monitor email traffic data to manage billing, to 
> handle customer enquiries, and for the prevention and detection of fraud. 
> We may also monitor the content of emails sent to and/or from Zen Internet 
> Limited for the purposes of security, staff training and to monitor the 
> quality of service.
> Zen Internet Limited is registered in England and Wales, Sandbrook Park, 
> Sandbrook Way, Rochdale, OL11 1RY Company No. 03101568 VAT Reg No. 686 0495 
> 01 
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c1d34990-620e-4228-bb1f-026e97fd1bddn%40googlegroups.com.


Re: [ansible-project] How to access the playbook execution log file at run time?

2024-06-16 Thread Will McDonald
If you're running Job Templates in AWX you might want to look into
Notification Templates (
https://ansible.readthedocs.io/projects/awx/en/latest/userguide/notifications.html),
and specifically Email (
https://ansible.readthedocs.io/projects/awx/en/latest/userguide/notifications.html#email
)

You could also look into callback plugins (
https://docs.ansible.com/ansible/latest/plugins/callback.html#example-callback-plugins
)

On Sun, 16 Jun 2024 at 15:56, Luiz Gustavo  wrote:

> Hey guys,
>
> How to access the playbook execution log file at run time? I would need to
> email it after running the playbook.
>
> For example, a simple playbook:
>
> ---
> - hosts: localhost
>   tasks:
>   - name: "display message"
> debug:
>   msg: "Hello"
>
> I would need to email the execution output:
>
>
>
>
>
>
>
>
>
>
>
>
> *PLAY [localhost]
> *TASK
> [Gathering Facts]
> ***ok:
> [localhost]TASK [display message]
> ***ok:
> [localhost] => {"msg": "Hello"}PLAY RECAP
> ***localhost
>  : ok=2changed=0unreachable=0failed=0
>  skipped=0rescued=0ignored=0   *
>
> PS.:
> I cannot set the ANSIBLE_LOG_PATH environment variable before executing
> the playbook because the execution will be done through AWX and not through
> the command line.
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAL-Q%3DKvUjWhhAE5mmhpU8r8FSS0EzkzKH-zGivBLf3%2BjZqq65Q%40mail.gmail.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAKtKohQPSyOmOQPN80nRTndRWARbuxBajJLoDdo8nSD45xQ_hQ%40mail.gmail.com.


Re: [ansible-project] Unknown Error HTTPSConnection.__init__

2024-06-16 Thread John Petro
Thanks.  I'll have to see if I can get that installed.  I tried last night
to get it installed, but didn't work out.  I'm pretty sure I know why
though, just have to mess with it more.  😊

On Sun, Jun 16, 2024, 9:27 AM Jorge Rúa  wrote:

> According to
> https://docs.python.org/3.12/library/http.client.html#http.client.HTTPSConnection
>
> Changed in version 3.12: The deprecated key_file,* cert_file* and
> check_hostname parameters have been removed.
>
> This was fixed in ansible-core version 2.16.0 (or above) thus the simple
> solution, if possible, is to run ansible-core version 2.16.0 or above.
>
> Regards
>
> El dom, 16 jun 2024 a las 13:39, John Petro ()
> escribió:
>
>> Hi all...  So posting here in a last resort because my google searches
>> have turned up nothing, or solutions that did not work for me.
>>
>> I have an ansible control-node that is running ubuntu 20.04.  Everything
>> has been working just fine... until yesterday  I have a new server in
>> my environment, running ubuntu 24.04.  When i was running my day0 playbook,
>> it failed on a role that uses get_url to grab a file from github.  I have
>> tried using a non-https url, I have tried setting the certificate
>> validation to false.  Nothing I do seems to work, to get it working for
>> that one host.  The other hosts in my homelab, all run the role just fine.
>>
>> So I was wondering if anyone has run into this where they got the error (
>> see below ) and how you got around it.
>>
>>
>> failed: [ubuntu] (item=username) => changed=false
>>   ansible_loop_var: item
>>   dest: /home/username/bin/tmux-cssh
>>   elapsed: 0
>>   gid: 100
>>   group: users
>>   item:
>> UserName: username
>>   mode: '0755'
>>   *msg: 'An unknown error occurred: HTTPSConnection.__init__() got an
>> unexpected keyword argument ''cert_file'''*
>>   owner: username
>>   size: 3530
>>   state: file
>>   uid: 1002
>>   url:
>> https://raw.githubusercontent.com/peikk0/tmux-cssh/master/tmux-cssh
>>
>> --
>> 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 [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/CAPAjob_hfNhx9vYghW_Gam-oNTf35gWQ%2BHyu5HP9%2BdOJw%2BOS9w%40mail.gmail.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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAFtje5NHregyaGah82Ba5uQ79pHewgL6nSkkBss5owY5Car_8Q%40mail.gmail.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAPAjob8EhkNvDoYxDCg5cBR3u8UxgeuHPJKxqdrmU%3DD1TTChpA%40mail.gmail.com.


Re: [ansible-project] Unknown Error HTTPSConnection.__init__

2024-06-16 Thread Jorge Rúa
According to
https://docs.python.org/3.12/library/http.client.html#http.client.HTTPSConnection

Changed in version 3.12: The deprecated key_file,* cert_file* and
check_hostname parameters have been removed.

This was fixed in ansible-core version 2.16.0 (or above) thus the simple
solution, if possible, is to run ansible-core version 2.16.0 or above.

Regards

El dom, 16 jun 2024 a las 13:39, John Petro ()
escribió:

> Hi all...  So posting here in a last resort because my google searches
> have turned up nothing, or solutions that did not work for me.
>
> I have an ansible control-node that is running ubuntu 20.04.  Everything
> has been working just fine... until yesterday  I have a new server in
> my environment, running ubuntu 24.04.  When i was running my day0 playbook,
> it failed on a role that uses get_url to grab a file from github.  I have
> tried using a non-https url, I have tried setting the certificate
> validation to false.  Nothing I do seems to work, to get it working for
> that one host.  The other hosts in my homelab, all run the role just fine.
>
> So I was wondering if anyone has run into this where they got the error (
> see below ) and how you got around it.
>
>
> failed: [ubuntu] (item=username) => changed=false
>   ansible_loop_var: item
>   dest: /home/username/bin/tmux-cssh
>   elapsed: 0
>   gid: 100
>   group: users
>   item:
> UserName: username
>   mode: '0755'
>   *msg: 'An unknown error occurred: HTTPSConnection.__init__() got an
> unexpected keyword argument ''cert_file'''*
>   owner: username
>   size: 3530
>   state: file
>   uid: 1002
>   url: https://raw.githubusercontent.com/peikk0/tmux-cssh/master/tmux-cssh
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAPAjob_hfNhx9vYghW_Gam-oNTf35gWQ%2BHyu5HP9%2BdOJw%2BOS9w%40mail.gmail.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAFtje5NHregyaGah82Ba5uQ79pHewgL6nSkkBss5owY5Car_8Q%40mail.gmail.com.


Re: [ansible-project] How to run multiple playbooks concurrently in parallel

2024-06-10 Thread [email protected]
Thank you so much again Todd. It works and confirmed.

On Friday, June 7, 2024 at 5:12:41 PM UTC-5 Todd Lewis wrote:

> Try this:
> server_job.sh
>
> ansible-playbook main_job.yml -e "server=job1" --limit runtime-host-group &
> ansible-playbook main_job.yml -e "server=job2" --limit runtime-host-group &
> ansible-playbook main_job.yml -e "server=job3" --limit runtime-host-group &
> ansible-playbook main_job.yml -e "server=job4" --limit runtime-host-group &
> wait
>
>
> On 6/7/24 5:46 PM, [email protected] wrote:
>
> Hello Group,
>
> Is there a way that I can run a playbook concurrently?
>
> Currently, if I'm running the script with multiple playbook (2x or 3x or 
> so), it will run and finish the first playbook before proceeding on the 
> next playbook in the line.
>
> The idea is that I want to run a script that has multiple playbooks (2x or 
> 3x or so) concurrently in parallel at the same time. Meaning, the job1, 
> job2, job3, and job4 will run at the same time and should NOT wait to 
> finish each other.
>
> Any help and guidance is highly appreciated.
>
>
> An example of the scenarios are below.
> Scenarios
> shell script
> /home/fuser/scripts/ansbile/playbooks/servers/server_job.sh
>
> server_job.sh
> ansible-playbook main_job.yml -e "server=job1" --limit runtime-host-group
> ansible-playbook main_job.yml -e "server=job2" --limit runtime-host-group
> ansible-playbook main_job.yml -e "server=job3" --limit runtime-host-group
> ansible-playbook main_job.yml -e "server=job4" --limit runtime-host-group
>
> runtime-host-group 
> [runtime-host-group]
> runtime001
> runtime002
>
> main_job.yml (using import_playbook)
> - name: Playbook to Stop/Start
>   hosts: all
> - name: Stop-Runtime | Stop the Runtime
>   import_playbook: 
> "/home/fuser/scripts/ansbile/playbooks/servers/playbook_sbxrun_runtime_stop_systemCTL.yml"
> - name: Start-Runtime | Start the Runtime
>   import_playbook: 
> "/home/fuser/scripts/ansbile/playbooks/servers/playbook_sbxrun_runtime_start_systemCTL.yml"
>
> playbook_sbxrun_runtime_stop_systemCTL.yml
> - name: Process to STOP
>   hosts: all
>   tasks:
> - name: SystemCTL | STOP
>   service:
> name: "{{ item }}"
> state: stopped
>   become: yes
>   with_items:
> - runtime-{{server}}.service
> - monitor-{{server}}.service
>
> playbook_sbxrun_runtime_start_systemCTL.yml
> - name: Process to START
>   hosts: all
>   tasks:
> - name: SystemCTL | STOP
>   service:
> name: "{{ item }}"
> state: started
>   become: yes
>   with_items:
> - runtime-{{server}}.service
> - monitor-{{server}}.service
>
>
> Thank you
> Erwin
>
> -- 
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/f996beb8-5458-4194-817b-33ee6221713bn%40googlegroups.com
>  
> 
> .
>
>
> -- 
> Todd
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/116f5bec-de00-4b73-9c37-f3a85f4ddc17n%40googlegroups.com.


Re: [ansible-project] How to run multiple playbooks concurrently in parallel

2024-06-07 Thread Todd Lewis

Try this:
server_job.sh

   ansible-playbook main_job.yml -e "server=job1" --limit runtime-host-group &
   ansible-playbook main_job.yml -e "server=job2" --limit runtime-host-group &
   ansible-playbook main_job.yml -e "server=job3" --limit runtime-host-group &
   ansible-playbook main_job.yml -e "server=job4" --limit runtime-host-group &
   wait


On 6/7/24 5:46 PM, [email protected] wrote:

Hello Group,

Is there a way that I can run a playbook concurrently?

Currently, if I'm running the script with multiple playbook (2x or 3x 
or so), it will run and finish the first playbook before proceeding on 
the next playbook in the line.


The idea is that I want to run a script that has multiple playbooks 
(2x or 3x or so) concurrently in parallel at the same time. Meaning, 
the job1, job2, job3, and job4 will run at the same time and should 
NOT wait to finish each other.


Any help and guidance is highly appreciated.


An example of the scenarios are below.
Scenarios
shell script
/home/fuser/scripts/ansbile/playbooks/servers/server_job.sh

server_job.sh
ansible-playbook main_job.yml -e "server=job1" --limit runtime-host-group
ansible-playbook main_job.yml -e "server=job2" --limit runtime-host-group
ansible-playbook main_job.yml -e "server=job3" --limit runtime-host-group
ansible-playbook main_job.yml -e "server=job4" --limit runtime-host-group

runtime-host-group
[runtime-host-group]
runtime001
runtime002

main_job.yml (using import_playbook)
- name: Playbook to Stop/Start
hosts: all
- name: Stop-Runtime | Stop the Runtime
import_playbook: 
"/home/fuser/scripts/ansbile/playbooks/servers/playbook_sbxrun_runtime_stop_systemCTL.yml"

- name: Start-Runtime | Start the Runtime
import_playbook: 
"/home/fuser/scripts/ansbile/playbooks/servers/playbook_sbxrun_runtime_start_systemCTL.yml"


playbook_sbxrun_runtime_stop_systemCTL.yml
- name: Process to STOP
hosts: all
tasks:
    - name: SystemCTL | STOP
service:
name: "{{ item }}"
state: stopped
become: yes
with_items:
        - runtime-{{server}}.service
        - monitor-{{server}}.service

playbook_sbxrun_runtime_start_systemCTL.yml
- name: Process to START
hosts: all
tasks:
    - name: SystemCTL | STOP
service:
name: "{{ item }}"
state: started
become: yes
with_items:
        - runtime-{{server}}.service
        - monitor-{{server}}.service


Thank you
Erwin
--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f996beb8-5458-4194-817b-33ee6221713bn%40googlegroups.com 
.


--
Todd

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/56de71fe-3a5e-442e-a519-747fba76a8c7%40gmail.com.


Re: [ansible-project] Variable within the variable

2024-06-07 Thread [email protected]
Thank you so much Todd. I will try and test your suggestion.

On Wednesday, June 5, 2024 at 7:22:40 AM UTC-5 Todd Lewis wrote:

> You need to make your fuser_dirname variable change as you loop over your 
> car models.
> Then you need to make your tasks loop over the car models.
>
> - name: Create and copy folder
>   hosts: all
>   become_user: fuser
>
>   vars_files:
> - /ansible_scripts/vars/vars_carmodel_file.yml
>
>   vars:
> fuser_dirname: "*{{ item }}-sample-dir*"
>
>   tasks:
> - name: Create sample directories in /home/mule
>   ansible.builtin.file:
> path: "/home/mule/{{ fuser_dirname }}"
> mode: "0755"
> state: directory
>   *loop: "{{ car_dirname }}"*
>
> - name: Copy /home/fuser directories to /apps
>   ansible.builtin.copy:
> src: "/home/fuser/{{ fuser_dirname }}/"
> dest: "/apps/{{ fuser_dirname }}"
>   *loop: "{{ car_dirname }}"*
>
> But there's lots of other questionable stuff going on here. The first task 
> is working in the target hosts /home/mule directory, but the second task 
> is copying directories from the ansible controller's /home/fuser tree to 
> the target hosts without specifying group, owner, or mode.
>
> Anyway, this is one answer to how to deal with the looping. You'll need to 
> work out these other details, though, before you have a useful process.
>
> Also, use ansible-lint on your code.
>
>
> On 5/30/24 4:15 PM, [email protected] wrote:
>
> Hello Group,
>
> Requesting for any help and guidance on how I can able to use the variable 
> within the variables.
>
> I have the variable (fuser_dirname) that I'd usually used as the main 
> variable in my playbook. However, I'd just need to have another variable 
> with the list of the car name to make it as directory name.
>
> This maybe similar to the bash script where I will cat the variable file 
> then use the 'for' loop command.
>
> Was wondering if anyone may have some idea on how to work this in just 
> playbook module and script.
>
> Below are the command, expected result, variable, and playbook files.
>
> Command
>   ansible-playbook /ansible_scripts/playbooks/testtemp/for_test_only.yml 
> --limit fuser_hostname  
>
> Result
> fuserATawscar001:/apps> ls -l
> drwxr-xr-x 3 fuser fuser33 May 30 08:40 honda-sample-dir/
> drwxr-xr-x 3 fuser fuser33 May 30 08:40 tesla-sample-dir/
> drwxr-xr-x 3 fuser fuser33 May 30 08:40 tesla-sample-dir/
>
> Variable File
> /ansible_scripts/vars/vars_carmodel_file.yml
> car_dirname:
>   - honda
>   - toyota
>   - tesla
>
> Playbook File
> - name: Create and copy folder
>   hosts: all
>   become_user: fuser
>   vars_files:
> - /ansible_scripts/vars/vars_carmodel_file.yml
>   vars:
> fuser_dirname: (( fuser_folder ))-sample-dir
>   
>   tasks:
> - name: create
>   file:
> path: "/home/mule/{{ fuser_dirname }}"
> mode: 0755
> state: directory
> - name: copy
>   copy:
> src: "/home/fuser/{{ fuser_dirname }}/"
> dest: "/apps/{{ fuser_dirname }}"
>
>
> Any help and guidance are much appreciated.
>
>
> Thank you so much in advance.
>
> -- 
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/a7edd5a7-90df-4087-b56a-4c4bad72f2e5n%40googlegroups.com
>  
> 
> .
>
>
> -- 
> Todd
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/adf8382c-ace0-4321-8775-496a6719fc7fn%40googlegroups.com.


Re: [ansible-project] Variable within the variable

2024-06-05 Thread Todd Lewis
You need to make your fuser_dirname variable change as you loop over 
your car models.

Then you need to make your tasks loop over the car models.

- name: Create and copy folder
  hosts: all
  become_user: fuser

  vars_files:
- /ansible_scripts/vars/vars_carmodel_file.yml

  vars:
fuser_dirname: "*{{ item }}-sample-dir*"

  tasks:
- name: Create sample directories in /home/mule
  ansible.builtin.file:
path: "/home/mule/{{ fuser_dirname }}"
mode: "0755"
state: directory
  *loop: "{{ car_dirname }}"*

- name: Copy /home/fuser directories to /apps
  ansible.builtin.copy:
src: "/home/fuser/{{ fuser_dirname }}/"
dest: "/apps/{{ fuser_dirname }}"
  *loop: "{{ car_dirname }}"*

But there's lots of other questionable stuff going on here. The first 
task is working in the target hosts /home/mule directory, but the second 
task is copying directories from the ansible controller's /home/fuser 
tree to the target hosts without specifying group, owner, or mode.


Anyway, this is one answer to how to deal with the looping. You'll need 
to work out these other details, though, before you have a useful process.


Also, use ansible-lint on your code.

On 5/30/24 4:15 PM, [email protected] wrote:

Hello Group,

Requesting for any help and guidance on how I can able to use the 
variable within the variables.


I have the variable (fuser_dirname) that I'd usually used as the main 
variable in my playbook. However, I'd just need to have another 
variable with the list of the car name to make it as directory name.


This maybe similar to the bash script where I will cat the variable 
file then use the 'for' loop command.


Was wondering if anyone may have some idea on how to work this in just 
playbook module and script.


Below are the command, expected result, variable, and playbook files.

Command
ansible-playbook /ansible_scripts/playbooks/testtemp/for_test_only.yml 
--limit fuser_hostname


Result
fuserATawscar001:/apps> ls -l
drwxr-xr-x 3 fuser fuser    33 May 30 08:40 honda-sample-dir/
drwxr-xr-x 3 fuser fuser    33 May 30 08:40 tesla-sample-dir/
drwxr-xr-x 3 fuser fuser    33 May 30 08:40 tesla-sample-dir/

Variable File
/ansible_scripts/vars/vars_carmodel_file.yml
car_dirname:
      - honda
      - toyota
      - tesla

Playbook File
- name: Create and copy folder
hosts: all
become_user: fuser
vars_files:
    - /ansible_scripts/vars/vars_carmodel_file.yml
vars:
fuser_dirname: (( fuser_folder ))-sample-dir
tasks:
    - name: create
file:
path: "/home/mule/{{ fuser_dirname }}"
mode: 0755
state: directory
    - name: copy
copy:
src: "/home/fuser/{{ fuser_dirname }}/"
dest: "/apps/{{ fuser_dirname }}"


Any help and guidance are much appreciated.


Thank you so much in advance.

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a7edd5a7-90df-4087-b56a-4c4bad72f2e5n%40googlegroups.com 
.


--
Todd

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/67ec8f2d-dfbb-49d9-b3a7-5dccb9e675fb%40gmail.com.


Re: [ansible-project] ansible.builtin.copy temp file

2024-06-03 Thread Brian Coca
The shell plugin controls that:
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/sh_shell.html#parameter-remote_tmp


-- 
--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7ctZGBC4y-zJxv9AAQ6J2FGh%3DLnKMXx0k4raGjP3o6c-g%40mail.gmail.com.


Re: [ansible-project] Multi-conditional when statements

2024-05-30 Thread John Petro
Thanks Brian!  That totally makes sense, and I hadn't even thought about it
that way.  Thanks for the help, it is very much appreciated.

--John

On Thu, May 30, 2024 at 12:28 PM Brian Coca  wrote:

> First of all, both are valid ways of writing conditionals.
>
> From the execution standpoint, the main difference is that the list
> version will be evaluated in order, one at a time by Ansible passing
> each item to Jinja.  While the other one will be passed as one item
> into Jinja. This creates a minor change in efficiency depending on the
> amount of conditions and the likelyhood of failure, but for most cases
> (less than 100 conditionals) I would consider it negligible.
>
> From a practical standpoint, the 2nd form is easier to put into a
> variable and compose 'ANDed' conditions by adding to a list, you only
> need to ensure each condition's correctness, not the aggregated whole.
> The first form on the other hand supports 'OR' conditions also.
>
> In the end I would consider it a preference issue, though most Ansible
> users are used to the 2nd form and might get confused by the first,
> but that is only a consideration when/if sharing the content.
>
> --
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CACVha7fDShTB-g-68uo%3DnMAqZXOVM2Oq3i%2BWUsGgM-nGXSNiRg%40mail.gmail.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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAPAjob8sruX%3DsYLdAcn2Cmb6-sVkm1p_g5K5MfHuxxuv1vddNA%40mail.gmail.com.


Re: [ansible-project] Multi-conditional when statements

2024-05-30 Thread Brian Coca
First of all, both are valid ways of writing conditionals.

>From the execution standpoint, the main difference is that the list
version will be evaluated in order, one at a time by Ansible passing
each item to Jinja.  While the other one will be passed as one item
into Jinja. This creates a minor change in efficiency depending on the
amount of conditions and the likelyhood of failure, but for most cases
(less than 100 conditionals) I would consider it negligible.

>From a practical standpoint, the 2nd form is easier to put into a
variable and compose 'ANDed' conditions by adding to a list, you only
need to ensure each condition's correctness, not the aggregated whole.
The first form on the other hand supports 'OR' conditions also.

In the end I would consider it a preference issue, though most Ansible
users are used to the 2nd form and might get confused by the first,
but that is only a consideration when/if sharing the content.

-- 
--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7fDShTB-g-68uo%3DnMAqZXOVM2Oq3i%2BWUsGgM-nGXSNiRg%40mail.gmail.com.


Re: [ansible-project] set module_defaults globally?

2024-05-29 Thread Vladimir Botka
On Tue, 28 May 2024 14:05:51 +0200
Dick Visser  wrote:

> I can use a variable for it (I think) ...

Top level keys must be static. Quoting from ansible-core
2.12 Release notes:
https://github.com/ansible/ansible/blob/stable-2.12/changelogs/CHANGELOG-v2.12.rst#breaking-changes--porting-guide

Breaking Changes / Porting Guide:

* Action, module, and group names in module_defaults must
  be static values. Their values can still be templates.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20240529155917.76aed10f%40plana.


pgpbalL6tVthQ.pgp
Description: OpenPGP digital signature


Re: [ansible-project] set module_defaults globally?

2024-05-29 Thread Vladimir Botka
On Wed, 29 May 2024 07:42:37 +0200
"'Felix Fontein' via Ansible Project"
 wrote:

Hi all,

> > At that point copy the module into a custom one and set
> > the defaults you want.  
> 
> ... allow module defaults to be included instead of
> having to re-specify them in every play
> (include_module_defaults: my-defaults.yaml).

FWIW, a substitution would solve many use-cases

```yaml
- hosts: all
  module_defaults: "{{ mdefaults }}"
  ...
```

Unfortunately, it fails:

ERROR! The field 'module_defaults' is supposed to be a
dictionary or list of dictionaries, the keys of which must
be static action, module, or group names. Only the values
may contain templates. For example: {'ping': "{{
ping_defaults }}"}

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20240529154417.51e55679%40plana.


pgpjPvkHDY87W.pgp
Description: OpenPGP digital signature


Re: [ansible-project] set module_defaults globally?

2024-05-28 Thread 'Felix Fontein' via Ansible Project
Hi Brian and Dick,

> At that point copy the module into a custom one and set the defaults
> you want.

that doesn't sound very sustainable, especially if this is the case for
multiple modules in multiple collections.

It might be helpful to allow module defaults to be included instead of
having to re-specify them in every play (include_module_defaults:
my-defaults.yaml).

You'll still have to add that include to all your plays then, but at
least you only have to do it once (and even can use a linting rule to
make sure that all your plays include that default) and have a single
place where to fill these defaults in.

Cheers,
Felix

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20240529074237.3cdc8156%40rovaniemi.


Re: [ansible-project] set module_defaults globally?

2024-05-28 Thread Brian Coca
At that point copy the module into a custom one and set the defaults you want.

-- 
--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7ejfcpTdfKbv%3DXz3%3D5zqaUKPekLrvAKwmEgH7Gx_HNYfA%40mail.gmail.com.


Re: [ansible-project] Re: Is there a task/module to create a vaulted file?

2024-05-28 Thread Andrew Latham
I saw https://github.com/ansible/ansible/pull/79864 which is related. I am
interested in this as it sounds useful to many. I wildly assume the
solution is obvious. Maybe drop the token into a local dir and a later task
can encrypt any files found in said dir and copy them to the vars dir of
your choice.

On Tue, May 28, 2024 at 8:18 AM Dick Visser  wrote:

>
>
> On Tue, 28 May 2024 at 15:42, Andrew Latham  wrote:
>
>> Unable to test from current location but do you need to delegate_to for
>> this?
>>
>
> Yes, I didn't explicitly mention it, but I'm running all the tasks from a
> dedicated "local" play with these settings:
>
> - name: API tasks
>   hosts: foo_hosts
>   # This is an API-only play, so we run it locally - not from the actual
> hosts
>   connection: local
>   become: false
>   gather_facts: false
>   tags: foo,always
>   run_once: true
>
>   tasks:
> - name: blah
> 
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAF8BbLZ3mhSSEVkr9AJQHuFvk9xjHRPfLqj%2BbgE-0jOMHShTwQ%40mail.gmail.com
> 
> .
>


-- 
- Andrew "lathama" Latham -

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CA%2Bqj4S-PTNUHyUZK7rudfV1sn1YaBwR6AWWQvtZF_BnBQ3voPg%40mail.gmail.com.


Re: [ansible-project] Re: Is there a task/module to create a vaulted file?

2024-05-28 Thread Dick Visser
On Tue, 28 May 2024 at 15:42, Andrew Latham  wrote:

> Unable to test from current location but do you need to delegate_to for
> this?
>

Yes, I didn't explicitly mention it, but I'm running all the tasks from a
dedicated "local" play with these settings:

- name: API tasks
  hosts: foo_hosts
  # This is an API-only play, so we run it locally - not from the actual
hosts
  connection: local
  become: false
  gather_facts: false
  tags: foo,always
  run_once: true

  tasks:
- name: blah


-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAF8BbLZ3mhSSEVkr9AJQHuFvk9xjHRPfLqj%2BbgE-0jOMHShTwQ%40mail.gmail.com.


Re: [ansible-project] Re: Is there a task/module to create a vaulted file?

2024-05-28 Thread Andrew Latham
Unable to test from current location but do you need to delegate_to for
this?

On Tue, May 28, 2024 at 7:23 AM Dick Visser  wrote:

>
>
> On Tue, 28 May 2024 at 15:17, Dick Visser  wrote:
>
>>
>> This seems to work, and because ansible.cfg contains the right
>> information (vault_identity_list, vault_encrypt_identity) the encrypted
>> content looks good, when I'm debugging.
>> But the actual file contents are plain text again. It seems the copy
>> module decrypts the encrypted content again? How can I force the content to
>> NOT be decrypted?
>>
>
> To quickly answer my own question: there is a decrypt parameter:
> https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html#parameter-decrypt
> I had never noticed that 🤡
>
> So the first task does work now.
>
> Still my other question remains:
>
>
>> Another approach is the vault filter, which seems to be a bit cleaner. I
>> thought this would do the trick:
>>
>> - name: save token
>>   ansible.builtin.copy:
>> content: "{{ token | ansible.builtin.vault }}"
>> dest: /tmp/out2
>> mode: 0600
>>
>> But that didn't work, the filter insists on an actual secret value. I
>> then must do a separate lookup for the ansible vault password. But the
>> vault password file can also be an executable that sends the secret to
>> stdout. I don't want to have to implement that logic myself.
>>
>> Is there a way for the ansible.builtin.vault filter to use the
>> vault_identity_list and vault_encrypt_identity that are in ansible.cfg?
>>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAF8BbLYAsqbxCdZf8CU51%3DjCw5MJT-rwg%3DYweT7R%2BU6n4kAMLg%40mail.gmail.com
> 
> .
>


-- 
- Andrew "lathama" Latham -

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CA%2Bqj4S890JNmisy6LkoHkJN8RA1_neDHmCL1XP0e7EwRm-Gx7w%40mail.gmail.com.


Re: [ansible-project] Looping through a register variable

2024-05-28 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
Very subtle but very different. Great catch Todd.

In the first instance you create a list that contains a single item – another 
list called known.stdout_lines.

loop:
  - '{{ known.stdout_lines }}'

In the second instance you provide a list called known.stdout_lines as the list 
for the loop:

loop: '{{ known.stdout_lines }}'

The second instance is the desired behavior. The difference is subtle at first 
glance but makes a world of difference in execution.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On May 23, 2024, at 11:30 AM, Todd Lewis  wrote:

Gah! Of course. known.stdout_lines is a list, so

loop:
  - '{{ known.stdout_lines }}'


passes the whole list as a single item. So you need to not put the list in a 
list:

loop: '{{ known.stdout_lines }}'


should do the trick.
—
Todd

On 5/23/24 11:17 AM, Dimitri Yioulos wrote:
Todd, I made the change, but, the last play failed:

TASK [Append to all known_host files] 
*
Thursday 23 May 2024  11:06:33 -0400 (0:00:01.629)   0:00:06.012 **
Thursday 23 May 2024  11:06:33 -0400 (0:00:01.629)   0:00:06.011 **
failed: [myhost] (item=['/root/.ssh/known_hosts', 
'/home/user1/.ssh/known_hosts', '/home/user2/.ssh/known_hosts', 
'/home/user3/.ssh/known_hosts', '/home/user4/.ssh/known_hosts']) => changed=true
  ansible_loop_var: item
  cmd: cat /tmp/append >> ['/root/.ssh/known_hosts', 
'/home/user1/.ssh/known_hosts', '/home/user2/.ssh/known_hosts', 
'/home/user3/.ssh/known_hosts', '/home/user4/.ssh/known_hosts']
  delta: '0:00:00.012330'
  end: '2024-05-23 11:06:33.947617'
  item:
  - /root/.ssh/known_hosts
  - /home/user1/.ssh/known_hosts
  - /home/user2/.ssh/known_hosts
  - /home/user3/.ssh/known_hosts
  - /home/user4/.ssh/known_hosts
  msg: non-zero return code
  rc: 1
  start: '2024-05-23 11:06:33.935287'
  stderr: '/bin/sh: line 1: [/root/.ssh/known_hosts,: No such file or directory'
  stderr_lines: 
  stdout: ''
  stdout_lines: 

I wonder if [ in  [/root/.ssh/known_hosts is getting in the way, since  
/root/.ssh/known_host does exist.

On Thursday, May 23, 2024 at 10:50:28 AM UTC-4 Todd Lewis wrote:
You want stdout_lines rather than stdout. The former is a list with new-lines 
removed. The latter is a possibly very long string with the complete output 
stream intact.

- name: Append to all known_host files
  shell: cat /tmp/append >> {{ item }}
  loop:
- '{{ known.stdout_lines }}'


On 5/23/24 9:07 AM, Dimitri Yioulos wrote:
Good day, all. I hope I'm not wearing out my welcome with too many questions.

In the following playbook, I first find any know_host file for any user on a 
particular system. I then copy a file with the list of additions to add to the 
known_hosts files. What I want to do is use the output of my register values to 
make changes to those know_host files, which my last play does. My iteration is 
wrong, though.

The playbook:

---

- hosts: all
  gather_facts: false
  become: yes

  vars:
script_path: 

Re: [ansible-project] Looping through a register variable

2024-05-28 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
Here is an illustration of the difference for those interested.



- name: test loop constructs

  hosts: localhost

  gather_facts: false

  become: false

  vars:

my_list: [ one, two, three ]

  tasks:

- name: construct 1

  debug: var=item

  loop:

- '{{ my_list }}'


- name: construct 2

  debug: var=item

  loop: '{{ my_list }}'





% ansible-playbook -i localhost, loop.yml


PLAY [test loop constructs] 



TASK [construct 1] 
*

ok: [localhost] => (item=['one', 'two', 'three']) => {

"ansible_loop_var": "item",

"item": [

"one",

"two",

"three"

]

}


TASK [construct 2] 
*

ok: [localhost] => (item=one) => {

"ansible_loop_var": "item",

"item": "one"

}

ok: [localhost] => (item=two) => {

"ansible_loop_var": "item",

"item": "two"

}

ok: [localhost] => (item=three) => {

"ansible_loop_var": "item",

"item": "three"

}


PLAY RECAP 
*

localhost  : ok=2changed=0unreachable=0failed=0
skipped=0rescued=0ignored=0



Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On May 24, 2024, at 7:41 AM, Rowe, Walter P. (Fed)  wrote:

Very subtle but very different. Great catch Todd.

In the first instance you create a list that contains a single item – another 
list called known.stdout_lines.

loop:
  - '{{ known.stdout_lines }}'

In the second instance you provide a list called known.stdout_lines as the list 
for the loop:

loop: '{{ known.stdout_lines }}'

The second instance is the desired behavior. The difference is subtle at first 
glance but makes a world of difference in execution.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

On May 23, 2024, at 11:30 AM, Todd Lewis  wrote:

Gah! Of course. known.stdout_lines is a list, so

loop:
  - '{{ known.stdout_lines }}'


passes the whole list as a single item. So you need to not put the list in a 
list:

loop: '{{ known.stdout_lines }}'


should do the trick.
—
Todd

On 5/23/24 11:17 AM, Dimitri Yioulos wrote:
Todd, I made the change, but, the last play failed:

TASK [Append to all known_host files] 
*
Thursday 23 May 2024  11:06:33 -0400 (0:00:01.629)   0:00:06.012 **
Thursday 23 May 2024  11:06:33 -0400 (0:00:01.629)   0:00:06.011 **
failed: [myhost] (item=['/root/.ssh/known_hosts', 
'/home/user1/.ssh/known_hosts', '/home/user2/.ssh/known_hosts', 
'/home/user3/.ssh/known_hosts', '/home/user4/.ssh/known_hosts']) => changed=true
  ansible_loop_var: item
  cmd: cat /tmp/append >> ['/root/.ssh/known_hosts', 
'/home/user1/.ssh/known_hosts', '/home/user2/.ssh/known_hosts', 
'/home/user3/.ssh/known_hosts', '/home/user4/.ssh/known_hosts']
  delta: '0:00:00.012330'
  end: '2024-05-23 11:06:33.947617'
  item:
  - /root/.ssh/known_hosts
  - /home/user1/.ssh/known_hosts
  - /home/user2/.ssh/known_hosts
  - /home/user3/.ssh/known_hosts
  - /home/user4/.ssh/known_hosts
  msg: non-zero return code
  rc: 1
  start: '2024-05-23 11:06:33.935287'
  stderr: '/bin/sh: line 1: [/root/.ssh/known_hosts,: No such file or directory'
  stderr_lines: 
  stdout: ''
  stdout_lines: 

I wonder if [ in  [/root/.ssh/known_hosts is getting in the way, since  
/root/.ssh/known_host does exist.

On Thursday, May 23, 2024 at 10:50:28 AM UTC-4 Todd Lewis wrote:
You want stdout_lines rather than stdout. The former is a list with new-lines 
removed. The latter is a possibly very long string with the complete output 
stream intact.

- name: Append to all known_host files
  shell: cat /tmp/append >> {{ item }}
  loop:
- '{{ known.stdout_lines }}'


On 5/23/24 9:07 AM, Dimitri Yioulos wrote:
Good day, all. I hope I'm not wearing out my welcome with too many questions.

In the following playbook, I first find any know_host file for any user on a 
particular system. I then copy a file with the list of additions to add to the 
known_hosts files. What I want to do is use the output of my register values to 
make changes to those know_host files, which my last play does. My iteration is 
wrong, though.

The playbook:

---

- hosts: all
  gather_facts: false
  become: yes

  vars:
script_path: 

Re: [ansible-project] Looping through a register variable

2024-05-23 Thread Dick Visser
Sent from Gmail Mobile


On Thu, May 23, 2024 at 16:50 Todd Lewis  wrote:

> You want stdout_lines rather than stdout. The former is a list with
> new-lines removed. The latter is a possibly very long string with the
> complete output stream intact.
>
> - name: Append to all known_host files
>   shell: cat /tmp/append >> {{ item }}
>   loop:
> - '{{ known.stdout_lines }}'
>
>
That should probably just loop over the list itself? So:

- name: Append to all known_host files
  shell: cat /tmp/append >> {{ item }}
  loop: '{{ known.stdout_lines }}'









> On 5/23/24 9:07 AM, Dimitri Yioulos wrote:
>
> Good day, all. I hope I'm not wearing out my welcome with too many
> questions.
>
> In the following playbook, I first find any know_host file for any user on
> a particular system. I then copy a file with the list of additions to add
> to the known_hosts files. What I want to do is use the output of my
> register values to make changes to those know_host files, which my last
> play does. My iteration is wrong, though.
>
> The playbook:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *--- - hosts: all   gather_facts: false   become: yes   vars:
> script_path: 

Re: [ansible-project] Looping through a register variable

2024-05-23 Thread Dimitri Yioulos
Yupper, that worked. And, I appreciate the explanation. As the Farber 
College motto states, "Learning is Good".

On Thursday, May 23, 2024 at 11:30:33 AM UTC-4 Todd Lewis wrote:

> Gah! Of course. known.stdout_lines is a list, so
>
> loop:
>   - '{{ known.stdout_lines }}'
>
> passes the whole list as a single item. So you need to not put the list in 
> a list:
>
> loop: '{{ known.stdout_lines }}'
>
> should do the trick.
> —
> Todd
>
>
> On 5/23/24 11:17 AM, Dimitri Yioulos wrote:
>
> Todd, I made the change, but, the last play failed:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *TASK [Append to all known_host files] 
> *
>  
> Thursday 23 May 2024  11:06:33 -0400 (0:00:01.629)   0:00:06.012 
> ** Thursday 23 May 2024  11:06:33 -0400 (0:00:01.629)   
> 0:00:06.011 ** failed: [myhost] (item=['/root/.ssh/known_hosts', 
> '/home/user1/.ssh/known_hosts', '/home/user2/.ssh/known_hosts', 
> '/home/user3/.ssh/known_hosts', '/home/user4/.ssh/known_hosts']) => 
> changed=true   ansible_loop_var: item   cmd: cat /tmp/append >> 
> ['/root/.ssh/known_hosts', '/home/user1/.ssh/known_hosts', 
> '/home/user2/.ssh/known_hosts', '/home/user3/.ssh/known_hosts', 
> '/home/user4/.ssh/known_hosts']   delta: '0:00:00.012330'   end: 
> '2024-05-23 11:06:33.947617'   item:   - /root/.ssh/known_hosts   - 
> /home/user1/.ssh/known_hosts   - /home/user2/.ssh/known_hosts   - 
> /home/user3/.ssh/known_hosts   - /home/user4/.ssh/known_hosts   msg: 
> non-zero return code   rc: 1   start: '2024-05-23 11:06:33.935287'   
> stderr: '/bin/sh: line 1: [/root/.ssh/known_hosts,: No such file or 
> directory'   stderr_lines:stdout: ''   stdout_lines: *
>
> I wonder if *[ *in  *[/root/.ssh/known_hosts* is getting in the way, 
> since  */root/.ssh/known_host* does exist.
>
> On Thursday, May 23, 2024 at 10:50:28 AM UTC-4 Todd Lewis wrote:
>
>> You want stdout_lines rather than stdout. The former is a list with 
>> new-lines removed. The latter is a possibly very long string with the 
>> complete output stream intact.
>>
>> - name: Append to all known_host files
>>   shell: cat /tmp/append >> {{ item }}
>>   loop:
>> - '{{ known.stdout_lines }}'
>>
>>
>> On 5/23/24 9:07 AM, Dimitri Yioulos wrote:
>>
>> Good day, all. I hope I'm not wearing out my welcome with too many 
>> questions.
>>
>> In the following playbook, I first find any know_host file for any user 
>> on a particular system. I then copy a file with the list of additions to 
>> add to the known_hosts files. What I want to do is use the output of my 
>> register values to make changes to those know_host files, which my last 
>> play does. My iteration is wrong, though.
>>
>> The playbook:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *--- - hosts: all   gather_facts: false   become: yes   vars: 
>> script_path: 

  1   2   3   4   5   6   7   8   9   10   >