Re: [ansible-project] Executing multiple roles in succession

2022-11-10 Thread Chris Bachmeyer
Hi, Walter,

I have everything running as it should.  It was my mistake.  I didn't
intend the full block in the initial email I sent this morning, only the
block for the second role.
The dynamic inventory is generated in the first role and passed to the
second, and the end-to-end deployment of instances on VMware now works
smoothly.

I haven't had time to look at restructuring the vars yet but thanks for the
input.

Really appreciate it!

Thanks again!

On Thu, Nov 10, 2022 at 10:55 AM 'Rowe, Walter P. (Fed)' via Ansible
Project  wrote:

> I have perused your reply but can't dig into it right at the moment. I
> will get back to it. Hopefully others also will chime in.
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services, OISM
> Mobile: 202.355.4123
>
> On Nov 10, 2022, at 12:28 PM, Christopher Bachmeyer <
> chris.bachme...@gmail.com> wrote:
>
> Initially, I set up the Ansible Playbook outside of using a role, a
> plays/, vars/, group_vars/, and collections/ directories.  Yes, the network
> and vc_locations were being passed
> in as extra_vars in Anbible Tower via  a Survey.
>
> As things have grown, I recently converted that work over to an Ansible
> role.  The conversion worked well and things run accordingly through
> Ansible Tower.  The site.yml is what
> is used including the vars_files sans the second role.  Now I am working
> on including the second role for post-processing needs of the deployed vms.
>
> Yes, the vmware-windows role needs variables defined for the vcenter,
> vlans, etc.  Currently, I have multiple ymls built out holding the vars
> such as:
>  vlan1.yml, vlan2.yml, etc.
>  vcenter1.yml, vcenter2.yml, etc.
> Doing it like this, I can have a prompt in the Survey for the Admins to
> customize the deployment.  I think I am following you, I can move those yml
> files over to tasks/ in the first role.
>
> I did indent the second role, having to remove the hyphen from "name."  In
> doing so, I received two warning:
>
> *"[WARNING]: While constructing a mapping from /tmp/bwrap_ ...
> /project/vmware-windows- role/provision.yml, line 3, column 3, found a
> duplicate dict key (name). Using last defined value only*
>
> # Windows would be the inventory for the second role
>
> *[WARNING]: Could not match supplied host pattern, ignoring: windows*
> Thanks!
> On Thursday, November 10, 2022 at 8:26:41 AM UTC-7 walte...@nist.gov
> wrote:
>
>> Does the vmware-windows role need the vars defined from the vars_files?
>> If so then the role itself should include them inside it's task file(s).
>> Move the vars_files inside tasks/main.yml. Anything the role does after
>> that will get the value of those vars definitions.
>>
>> The vmware-windows role will see the values of network and vc_location
>> that come into the playbook executing the role. I presume they come in as
>> extra_vars from command line or ansible tower.
>>
>>
>> Walter
>> --
>> Walter Rowe, Division Chief
>> Infrastructure Services, OISM
>> Mobile: 202.355.4123 <(202)%20355-4123>
>>
>> On Nov 10, 2022, at 9:54 AM, Christopher Bachmeyer 
>> wrote:
>>
>> Hi, Walter,
>>
>> That is correct.  I am, the vmware-windows role is the first play and
>> creates the host_group "windows" to be used as inventory in the second
>> play.
>> Right now, the second role is not indented but let me give that a go this
>> morning.  I'm presuming to indent the entire block starting with the hyphen
>> ( - name:  )?
>>
>> Regarding the vars_files, use import statements in the vars/main.yml of
>> the first role?  I have multiple vars files under vars/ that are specific
>> to the vcenters
>> and vlans.  Using vars_files and variables in the Ansible Tower Survey
>> gives the Admins a way to customize the builds to the environment (which
>> works well!).
>>
>> Thank you!
>>
>> On Thursday, November 10, 2022 at 5:23:04 AM UTC-7 walte...@nist.gov
>> wrote:
>>
>>> You need to make sure you use proper indentation. Your roles list needs
>>> to be indented two spaces like your vars_files.
>>>
>>> Is it possible also that your sourcing of those the vars_files from
>>> within your role is overwriting the value of "windows" such that there is
>>> no inventory for the second play? Why do you source those vars files? The
>>> vmware-windows role will do that automatically.
>>>
>>> - name: VMware-windows create role
>>>   hosts: localhost
>>>   gather_facts: no
>>>   roles:
>>> - vmware-windows
>>>
>>>
>>> ### this vars_files should not be needed
>>>
>>>
>>>   vars_files:
>>> - ./roles/vmware-windows/vars/{{ vc_location }}.yml
>>> - ./roles/vmware-windows/vars/{{ network }}.yml
>>>
>>>
>>> - name: Windows-post role
>>>   hosts: windows
>>>   gather_facts: no
>>>   roles:
>>> - windows-post
>>>
>>>
>>>
>>> I presume that your vmware-windows role in the first play creates the
>>> host group called "windows" that you use as the inventory in your second
>>> play?
>>>
>>> Walter
>>> --
>>> Walter Rowe, Division Chief
>>> Infrastructure Servic

[ansible-project] Looking for a string inside a register

2022-11-10 Thread dudu.c...@gmail.com


i’m running an API call in order to get indexes in Elastic – The output is 
saved inside a registry (index_list).

I want to run an additional job that runs only in case the policy name can 
be found in the register output – The solution I gave is not working (I’m 
guessing that I need to loop inside the registry on specific fields ) -

in the example below i have a policy ID named *what*


*API Call*

 - name: Get ISM_retention policy
  uri:
url: http://elastic:9200/_opendistro/_ism/policies
method: GET
timeout: 180
body_format: json
  register: index_list


*The debug condition that I’m trying to run –* In the register output you 
can find the *u'policy_id': u'what'*

- debug: msg: hello 
  when: “'what' in index_list”

*The register output*

MSG:  (I have marked the policy ID in bold)

{u'status': 200, u'content_length': u'1919', u'cookies': {}, u'url': 
u'http://elastic:9200/_opendistro/_ism/policies', u'changed': False, 
u'elapsed': 0, u'failed': False, u'json': {u'total_policies': 3, 
u'policies': [{u'policy': {u'default_state': u'hot', u'description': 
u'policy for delete index', u'last_updated_time': 1667984798760, 
u'error_notification': None, u'states': [{u'transitions': [{u'conditions': 
{u'min_index_age': u'1d'}, u'state_name': u'delete'}], u'name': u'hot', 
u'actions': [{u'retry': {u'count': 3, u'delay': u'1m', u'backoff': 
u'exponential'}, u'open': {}}]}, {u'transitions': [], u'name': u'delete', 
u'actions': [{u'retry': {u'count': 3, u'delay': u'1m', u'backoff': 
u'exponential'}, u'delete': {}}]}], u'ism_template': [{u'index_patterns': 
[u'audit-*'], u'priority': 100, u'last_updated_time': 1667984798760}], 
u'schema_version': 15, u'policy_id': u'policy_1'}, u'_id': u'policy_1', 
u'_seq_no': 104149, u'_primary_term': 1}, {u'policy': {u'default_state': 
u'hot', u'description': u'kuku index retenation flow', 
u'last_updated_time': 1668061803458, u'error_notification': None, 
u'states': [{u'transitions': [{u'conditions': {u'min_index_age': u'1d'}, 
u'state_name': u'delete'}], u'name': u'hot', u'actions': [{u'retry': 
{u'count': 3, u'delay': u'1m', u'backoff': u'exponential'}, u'open': {}}]}, 
{u'transitions': [], u'name': u'delete', u'actions': [{u'retry': {u'count': 
3, u'delay': u'1m', u'backoff': u'exponential'}, u'delete': {}}]}], 
u'ism_template': [{u'index_patterns': [u'kuku-*'], u'priority': 100, 
u'last_updated_time': 1668061803458}], u'schema_version': 15, u'policy_id': 
u'policy_kuku'}, u'_id': u'policy_kuku', u'_seq_no': 143284, 
u'_primary_term': 1}, {u'policy': {u'default_state': u'hot', 
u'description': u'what index retenation flow', u'last_updated_time': 
1668074528411, u'error_notification': None, u'states': [{u'transitions': 
[{u'conditions': {u'min_index_age': u'1d'}, u'state_name': u'delete'}], 
u'name': u'hot', u'actions': [{u'retry': {u'count': 3, u'delay': u'1m', 
u'backoff': u'exponential'}, u'open': {}}]}, {u'transitions': [], u'name': 
u'delete', u'actions': [{u'retry': {u'count': 3, u'delay': u'1m', 
u'backoff': u'exponential'}, u'delete': {}}]}], u'ism_template': 
[{u'index_patterns': [u'what-*'], u'priority': 100, u'last_updated_time': 
1668074528411}], u'schema_version': 15, *u'policy_id': u'what'*}, u'_id': 
u'what', u'_seq_no': 150078, u'_primary_term': 1}]}, u'content_type': 
u'application/json; charset=UTF-8', u'msg': u'OK (1919 bytes)', 
u'redirected': False, u'cookies_string': u''}




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


Re: [ansible-project] copy registered content to a file which is called from variable

2022-11-10 Thread Veera
Whatever "vars" is, it doesn't have any data with that name -  
exactly...  it will be a new file to be created by the copy's "dest ."


compare_out.stdout is having   the output of hundreds of lines to be 
printed parallely .  I have disabled the printing of its output (to reduce 
screen space) by 
register: compare_out
no_log: true 

###
Perhaps you mean this:

  dest="{{ comp_file }}"

Whatever. In any case, if I were you, I'd throw in a debug step and print 
out the values of "compare_out.stdout" and, er, whatever you think "dest" 
is supposed to be ("vars"? but I think you just mean "comp_file").
### ###
 on the above ,  I am trying to write the compare_out.stdout  which is 100+ 
lines  to a file which  have to created by  calling the variable "{{ 
comp_file }}"  as dest using copy .


may be we need template? Jinja ?  
Learn to study more ..  :-)



On Friday, November 11, 2022 at 1:34:15 AM UTC+5:30 uto...@gmail.com wrote:

> Wait a second. You're saying "{{ vars[ comp_file ] }}", but
>
>   
> comp_file="/home/user1/ansible/patching/logs/2022-11-10/server1-compare-2022-11-10.txt"
>
> So you're trying to pull a value from the "vars" dict with the key of
>   "
> /home/user1/ansible/patching/logs/2022-11-10/server1-compare-2022-11-10.txt
> ".
>
> Whatever "vars" is, it doesn't have any data with that name.
>
> Perhaps you mean this:
>
>   dest="{{ comp_file }}"
>
> Whatever. In any case, if I were you, I'd throw in a debug step and print 
> out the values of "compare_out.stdout" and, er, whatever you think "dest" 
> is supposed to be ("vars"? but I think you just mean "comp_file").
>
>
> On 11/10/22 1:26 PM, Veera wrote:
>
>
> Thanks for pointing  as i did notice that , and I have corrected the  
> three left braces on "exec_date". 
>
> Second, mustaches (i.e. "{{" … "}}") never nest  <<  Yes , I tried earlier 
> that and even now after reverting back , still the same issue .. 
> Execution error for the play below.
>
> fatal: [server1 -> localhost]: FAILED! => {"msg": "The task includes an 
> option with an undefined variable. The error was: 'dict object' has no 
> attribute 
> u'/home/user1/ansible/patching/logs/2022-11-10/server1-compare-2022-11-10.txt'\n\nThe
>  
> error appears to be in 
> '/home/unixops/ansible/linux_patching/compare_sanity.yml': line 7, column 
> 3, but may\nbe elsewhere in the file depending on the exact syntax 
> problem.\n\nThe offending line appears to be:\n\n\n- name: create compare 
> file using precheck and postcheck sanity checks\n  ^ here\n"}
>
>
> On Thursday, November 10, 2022 at 10:24:51 PM UTC+5:30 uto...@gmail.com 
> wrote:
>
>> A couple of things. First,
>>
>> comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
>> exec_date }}.txt
>>
>> has three left braces on "exec_date".
>>
>> Second, mustaches (i.e. "{{" … "}}") never nest. So
>>
>> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{ comp_file 
>> }} ] }}"
>>
>> should be
>>
>> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ comp_file ] 
>> }}"
>>
>> Well, at least that's "dest=" without nested mustaches. Whether it's 
>> right or not I don't know, but it's less wrong this way.
>>
>>
>> On 11/10/22 9:16 AM, Veera wrote:
>>
>> Hi, 
>>
>> I am trying to copy the  contents from a register output  to a file  in 
>> the local server.
>> However , I have challenges in re-calling the variable filename in the 
>> copy command.
>>
>> Correct me what I am missing. in dest="{{ vars[ {{ comp_file }} ] }}"  or 
>> "{{ compare_out.stdout }}"  in the last lines ..
>>
>>
>> [vee@server]$ grep comp_file  vars/postcheck_vars.yml
>> comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
>> exec_date }}.txt
>>
>> [vee@server]$ cat  compare_sanity.yml
>> - name: comparing file1 and file2 
>>   local_action: command /usr/bin/sdiff "{{ logs_dir }}"{{ 
>> inventory_hostname }}-Pre-{{ exec_date }}.txt   "{{ logs_dir }}"{{ 
>> inventory_hostname }}-Post-{{ exec_date }}.txt
>>   register: compare_out
>>   ignore_errors: yes
>>   no_log: True
>>
>> - name: create output  file
>>   local_action:
>> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{ comp_file 
>> }} ] }}"
>>   [vee@server]$
>>
>>
>

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


Re: [ansible-project] copy registered content to a file which is called from variable

2022-11-10 Thread Todd Lewis

Wait a second. You're saying "{{ vars[ comp_file ] }}", but

comp_file="/home/user1/ansible/patching/logs/2022-11-10/server1-compare-2022-11-10.txt"

So you're trying to pull a value from the "vars" dict with the key of
  
"/home/user1/ansible/patching/logs/2022-11-10/server1-compare-2022-11-10.txt".


Whatever "vars" is, it doesn't have any data with that name.

Perhaps you mean this:

  dest="{{ comp_file }}"

Whatever. In any case, if I were you, I'd throw in a debug step and 
print out the values of "compare_out.stdout" and, er, whatever you think 
"dest" is supposed to be ("vars"? but I think you just mean "comp_file").


On 11/10/22 1:26 PM, Veera wrote:


Thanks for pointing  as i did notice that , and I have corrected the 
three left braces on "exec_date".


Second, mustaches (i.e. "{{" … "}}") never nest  << Yes , I tried 
earlier that and even now after reverting back , still the same issue ..

Execution error for the play below.

fatal: [server1 -> localhost]: FAILED! => {"msg": "The task includes 
an option with an undefined variable. The error was: 'dict object' has 
no attribute 
u'/home/user1/ansible/patching/logs/2022-11-10/server1-compare-2022-11-10.txt'\n\nThe 
error appears to be in 
'/home/unixops/ansible/linux_patching/compare_sanity.yml': line 7, 
column 3, but may\nbe elsewhere in the file depending on the exact 
syntax problem.\n\nThe offending line appears to be:\n\n\n- name: 
create compare file using precheck and postcheck sanity checks\n  ^ 
here\n"}



On Thursday, November 10, 2022 at 10:24:51 PM UTC+5:30 
uto...@gmail.com wrote:


A couple of things. First,


comp_file: /logs/{{ exec_date }}/{{ inventory_hostname
}}-compare-{{{ exec_date }}.txt

has three left braces on "exec_date".

Second, mustaches (i.e. "{{" … "}}") never nest. So


    copy content="{{ compare_out.stdout }}" dest="{{ vars[ {{
comp_file }} ] }}"

should be


    copy content="{{ compare_out.stdout }}" dest="{{ vars[
comp_file ] }}"

Well, at least that's "dest=" without nested mustaches. Whether
it's right or not I don't know, but it's less wrong this way.


On 11/10/22 9:16 AM, Veera wrote:

Hi,

I am trying to copy the  contents from a register output  to a
file  in the local server.
However , I have challenges in re-calling the variable filename
in the copy command.

Correct me what I am missing. in dest="{{ vars[ {{ comp_file }} ]
}}"  or "{{ compare_out.stdout }}"  in the last lines ..


[vee@server]$ grep comp_file  vars/postcheck_vars.yml
comp_file: /logs/{{ exec_date }}/{{ inventory_hostname
}}-compare-{{{ exec_date }}.txt

[vee@server]$ cat  compare_sanity.yml
- name: comparing file1 and file2
  local_action: command /usr/bin/sdiff "{{ logs_dir }}"{{
inventory_hostname }}-Pre-{{ exec_date }}.txt "{{ logs_dir }}"{{
inventory_hostname }}-Post-{{ exec_date }}.txt
  register: compare_out
  ignore_errors: yes
  no_log: True

- name: create output  file
  local_action:
    copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{
comp_file }} ] }}"
  [vee@server]$




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


Re: [ansible-project] copy registered content to a file which is called from variable

2022-11-10 Thread Veera
Attaching a screenshot to show the format still miss something [image: 
IMG-2022-WA.jpg]

On Thursday, November 10, 2022 at 11:56:40 PM UTC+5:30 Veera wrote:

>
> Thanks for pointing  as i did notice that , and I have corrected the  
> three left braces on "exec_date".
>
> Second, mustaches (i.e. "{{" … "}}") never nest  <<  Yes , I tried earlier 
> that and even now after reverting back , still the same issue .. 
> Execution error for the play below.
>
> fatal: [server1 -> localhost]: FAILED! => {"msg": "The task includes an 
> option with an undefined variable. The error was: 'dict object' has no 
> attribute 
> u'/home/user1/ansible/patching/logs/2022-11-10/server1-compare-2022-11-10.txt'\n\nThe
>  
> error appears to be in 
> '/home/unixops/ansible/linux_patching/compare_sanity.yml': line 7, column 
> 3, but may\nbe elsewhere in the file depending on the exact syntax 
> problem.\n\nThe offending line appears to be:\n\n\n- name: create compare 
> file using precheck and postcheck sanity checks\n  ^ here\n"}
>
>
> On Thursday, November 10, 2022 at 10:24:51 PM UTC+5:30 uto...@gmail.com 
> wrote:
>
>> A couple of things. First,
>>
>> comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
>> exec_date }}.txt
>>
>> has three left braces on "exec_date".
>>
>> Second, mustaches (i.e. "{{" … "}}") never nest. So
>>
>> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{ comp_file 
>> }} ] }}"
>>
>> should be
>>
>> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ comp_file ] 
>> }}"
>>
>> Well, at least that's "dest=" without nested mustaches. Whether it's 
>> right or not I don't know, but it's less wrong this way.
>>
>>
>> On 11/10/22 9:16 AM, Veera wrote:
>>
>> Hi, 
>>
>> I am trying to copy the  contents from a register output  to a file  in 
>> the local server.
>> However , I have challenges in re-calling the variable filename in the 
>> copy command.
>>
>> Correct me what I am missing. in dest="{{ vars[ {{ comp_file }} ] }}"  or 
>> "{{ compare_out.stdout }}"  in the last lines ..
>>
>>
>> [vee@server]$ grep comp_file  vars/postcheck_vars.yml
>> comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
>> exec_date }}.txt
>>
>> [vee@server]$ cat  compare_sanity.yml
>> - name: comparing file1 and file2 
>>   local_action: command /usr/bin/sdiff "{{ logs_dir }}"{{ 
>> inventory_hostname }}-Pre-{{ exec_date }}.txt   "{{ logs_dir }}"{{ 
>> inventory_hostname }}-Post-{{ exec_date }}.txt
>>   register: compare_out
>>   ignore_errors: yes
>>   no_log: True
>>
>> - name: create output  file
>>   local_action:
>> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{ comp_file 
>> }} ] }}"
>>   [vee@server]$
>>
>>
>>

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


Re: [ansible-project] copy registered content to a file which is called from variable

2022-11-10 Thread Veera

Thanks for pointing  as i did notice that , and I have corrected the  three 
left braces on "exec_date".

Second, mustaches (i.e. "{{" … "}}") never nest  <<  Yes , I tried earlier 
that and even now after reverting back , still the same issue .. 
Execution error for the play below.

fatal: [server1 -> localhost]: FAILED! => {"msg": "The task includes an 
option with an undefined variable. The error was: 'dict object' has no 
attribute 
u'/home/user1/ansible/patching/logs/2022-11-10/server1-compare-2022-11-10.txt'\n\nThe
 
error appears to be in 
'/home/unixops/ansible/linux_patching/compare_sanity.yml': line 7, column 
3, but may\nbe elsewhere in the file depending on the exact syntax 
problem.\n\nThe offending line appears to be:\n\n\n- name: create compare 
file using precheck and postcheck sanity checks\n  ^ here\n"}


On Thursday, November 10, 2022 at 10:24:51 PM UTC+5:30 uto...@gmail.com 
wrote:

> A couple of things. First,
>
> comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
> exec_date }}.txt
>
> has three left braces on "exec_date".
>
> Second, mustaches (i.e. "{{" … "}}") never nest. So
>
> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{ comp_file 
> }} ] }}"
>
> should be
>
> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ comp_file ] 
> }}"
>
> Well, at least that's "dest=" without nested mustaches. Whether it's right 
> or not I don't know, but it's less wrong this way.
>
>
> On 11/10/22 9:16 AM, Veera wrote:
>
> Hi, 
>
> I am trying to copy the  contents from a register output  to a file  in 
> the local server.
> However , I have challenges in re-calling the variable filename in the 
> copy command.
>
> Correct me what I am missing. in dest="{{ vars[ {{ comp_file }} ] }}"  or 
> "{{ compare_out.stdout }}"  in the last lines ..
>
>
> [vee@server]$ grep comp_file  vars/postcheck_vars.yml
> comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
> exec_date }}.txt
>
> [vee@server]$ cat  compare_sanity.yml
> - name: comparing file1 and file2 
>   local_action: command /usr/bin/sdiff "{{ logs_dir }}"{{ 
> inventory_hostname }}-Pre-{{ exec_date }}.txt   "{{ logs_dir }}"{{ 
> inventory_hostname }}-Post-{{ exec_date }}.txt
>   register: compare_out
>   ignore_errors: yes
>   no_log: True
>
> - name: create output  file
>   local_action:
> copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{ comp_file 
> }} ] }}"
>   [vee@server]$
>
>
>

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


Re: [ansible-project] Executing multiple roles in succession

2022-11-10 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
I have perused your reply but can't dig into it right at the moment. I will get 
back to it. Hopefully others also will chime in.

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

On Nov 10, 2022, at 12:28 PM, Christopher Bachmeyer 
mailto:chris.bachme...@gmail.com>> wrote:

Initially, I set up the Ansible Playbook outside of using a role, a plays/, 
vars/, group_vars/, and collections/ directories.  Yes, the network and 
vc_locations were being passed
in as extra_vars in Anbible Tower via  a Survey.

As things have grown, I recently converted that work over to an Ansible role.  
The conversion worked well and things run accordingly through Ansible Tower.  
The site.yml is what
is used including the vars_files sans the second role.  Now I am working on 
including the second role for post-processing needs of the deployed vms.

Yes, the vmware-windows role needs variables defined for the vcenter, vlans, 
etc.  Currently, I have multiple ymls built out holding the vars such as:
 vlan1.yml, vlan2.yml, etc.
 vcenter1.yml, vcenter2.yml, etc.
Doing it like this, I can have a prompt in the Survey for the Admins to 
customize the deployment.  I think I am following you, I can move those yml 
files over to tasks/ in the first role.

I did indent the second role, having to remove the hyphen from "name."  In 
doing so, I received two warning:


"[WARNING]: While constructing a mapping from /tmp/bwrap_ ... 
/project/vmware-windows- role/provision.yml, line 3, column 3, found a 
duplicate dict key (name). Using last defined value only

# Windows would be the inventory for the second role

[WARNING]: Could not match supplied host pattern, ignoring: windows

Thanks!
On Thursday, November 10, 2022 at 8:26:41 AM UTC-7 
walte...@nist.gov wrote:
Does the vmware-windows role need the vars defined from the vars_files? If so 
then the role itself should include them inside it's task file(s). Move the 
vars_files inside tasks/main.yml. Anything the role does after that will get 
the value of those vars definitions.

The vmware-windows role will see the values of network and vc_location that 
come into the playbook executing the role. I presume they come in as extra_vars 
from command line or ansible tower.


Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123
On Nov 10, 2022, at 9:54 AM, Christopher Bachmeyer  wrote:

Hi, Walter,

That is correct.  I am, the vmware-windows role is the first play and creates 
the host_group "windows" to be used as inventory in the second play.
Right now, the second role is not indented but let me give that a go this 
morning.  I'm presuming to indent the entire block starting with the hyphen
( - name:  )?

Regarding the vars_files, use import statements in the vars/main.yml of the 
first role?  I have multiple vars files under vars/ that are specific to the 
vcenters
and vlans.  Using vars_files and variables in the Ansible Tower Survey gives 
the Admins a way to customize the builds to the environment (which works well!).

Thank you!

On Thursday, November 10, 2022 at 5:23:04 AM UTC-7 
walte...@nist.gov wrote:
You need to make sure you use proper indentation. Your roles list needs to be 
indented two spaces like your vars_files.

Is it possible also that your sourcing of those the vars_files from within your 
role is overwriting the value of "windows" such that there is no inventory for 
the second play? Why do you source those vars files? The vmware-windows role 
will do that automatically.

- name: VMware-windows create role
  hosts: localhost
  gather_facts: no
  roles:
- vmware-windows

### this vars_files should not be needed

  vars_files:
- ./roles/vmware-windows/vars/{{ vc_location }}.yml
- ./roles/vmware-windows/vars/{{ network }}.yml

- name: Windows-post role
  hosts: windows
  gather_facts: no
  roles:
- windows-post


I presume that your vmware-windows role in the first play creates the host 
group called "windows" that you use as the inventory in your second play?

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

On Nov 9, 2022, at 5:30 PM, Christopher Bachmeyer  wrote:

Hey all,

I have two roles that are included in my site.yml and the goal is to execute 
the second role as soon as the first role completes.  I have added a task to 
generate a dynamic inventory in the first role that the second role can use.  I 
have a job Template in Ansible Tower and the first role executes cleanly but 
job Template completes without the second role executing.

What am I missing?

- name: VMware-windows create role
  hosts: localhost
  gather_facts: no
  roles:
  - vmware-windows

  vars_files:
- ./roles/vmware-windows/vars/{{ vc_location }}.yml
- ./roles/vmware-windows/vars/{{ network }}.yml

- name: Windows-post role
  hosts: windows
  gather_facts: no
  roles:
  - windows-post

Thanks!

--
You received this

Re: [ansible-project] Executing multiple roles in succession

2022-11-10 Thread Christopher Bachmeyer
Initially, I set up the Ansible Playbook outside of using a role, a plays/, 
vars/, group_vars/, and collections/ directories.  Yes, the network and 
vc_locations were being passed 
in as extra_vars in Anbible Tower via  a Survey.  

As things have grown, I recently converted that work over to an Ansible 
role.  The conversion worked well and things run accordingly through 
Ansible Tower.  The site.yml is what
is used including the vars_files sans the second role.  Now I am working on 
including the second role for post-processing needs of the deployed vms. 

Yes, the vmware-windows role needs variables defined for the vcenter, 
vlans, etc.  Currently, I have multiple ymls built out holding the vars 
such as:
 vlan1.yml, vlan2.yml, etc.
 vcenter1.yml, vcenter2.yml, etc.  
Doing it like this, I can have a prompt in the Survey for the Admins to 
customize the deployment.  I think I am following you, I can move those yml 
files over to tasks/ in the first role. 

I did indent the second role, having to remove the hyphen from "name."  In 
doing so, I received two warning:

*"[WARNING]: While constructing a mapping from /tmp/bwrap_ ... 
/project/vmware-windows- role/provision.yml, line 3, column 3, found a 
duplicate dict key (name). Using last defined value only* 

# Windows would be the inventory for the second role

*[WARNING]: Could not match supplied host pattern, ignoring: windows*
Thanks!
On Thursday, November 10, 2022 at 8:26:41 AM UTC-7 walte...@nist.gov wrote:

> Does the vmware-windows role need the vars defined from the vars_files? If 
> so then the role itself should include them inside it's task file(s). Move 
> the vars_files inside tasks/main.yml. Anything the role does after that 
> will get the value of those vars definitions. 
>
> The vmware-windows role will see the values of network and vc_location 
> that come into the playbook executing the role. I presume they come in as 
> extra_vars from command line or ansible tower.
>
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services, OISM
> Mobile: 202.355.4123 <(202)%20355-4123>
>
> On Nov 10, 2022, at 9:54 AM, Christopher Bachmeyer  
> wrote:
>
> Hi, Walter,  
>
> That is correct.  I am, the vmware-windows role is the first play and 
> creates the host_group "windows" to be used as inventory in the second 
> play. 
> Right now, the second role is not indented but let me give that a go this 
> morning.  I'm presuming to indent the entire block starting with the hyphen 
> ( - name:  )? 
>
> Regarding the vars_files, use import statements in the vars/main.yml of 
> the first role?  I have multiple vars files under vars/ that are specific 
> to the vcenters 
> and vlans.  Using vars_files and variables in the Ansible Tower Survey 
> gives the Admins a way to customize the builds to the environment (which 
> works well!).
>
> Thank you! 
>
> On Thursday, November 10, 2022 at 5:23:04 AM UTC-7 walte...@nist.gov 
> wrote:
>
>> You need to make sure you use proper indentation. Your roles list needs 
>> to be indented two spaces like your vars_files. 
>>
>> Is it possible also that your sourcing of those the vars_files from 
>> within your role is overwriting the value of "windows" such that there is 
>> no inventory for the second play? Why do you source those vars files? The 
>> vmware-windows role will do that automatically. 
>>
>> - name: VMware-windows create role
>>   hosts: localhost   
>>   gather_facts: no
>>   roles:
>> - vmware-windows
>>
>>
>> ### this vars_files should not be needed
>>
>>
>>   vars_files:
>> - ./roles/vmware-windows/vars/{{ vc_location }}.yml
>> - ./roles/vmware-windows/vars/{{ network }}.yml
>>
>>
>> - name: Windows-post role
>>   hosts: windows
>>   gather_facts: no
>>   roles:
>> - windows-post
>>
>>
>>
>> I presume that your vmware-windows role in the first play creates the 
>> host group called "windows" that you use as the inventory in your second 
>> play?
>>
>> Walter
>> --
>> Walter Rowe, Division Chief
>> Infrastructure Services, OISM
>> Mobile: 202.355.4123 <(202)%20355-4123>
>>
>> On Nov 9, 2022, at 5:30 PM, Christopher Bachmeyer  
>> wrote:
>>
>> Hey all,  
>>
>> I have two roles that are included in my site.yml and the goal is to 
>> execute the second role as soon as the first role completes.  I have added 
>> a task to generate a dynamic inventory in the first role that the second 
>> role can use.  I have a job Template in Ansible Tower and the first role 
>> executes cleanly but job Template completes without the second role 
>> executing.  
>>
>> What am I missing?
>>
>> - name: VMware-windows create role
>>   hosts: localhost   
>>   gather_facts: no
>>   roles:
>>   - vmware-windows
>>
>>   vars_files:
>> - ./roles/vmware-windows/vars/{{ vc_location }}.yml
>> - ./roles/vmware-windows/vars/{{ network }}.yml
>>
>> - name: Windows-post role
>>   hosts: windows
>>   gather_facts: no
>>   roles:
>>   - windows-post
>>
>> Thanks!
>>
>> -- 

Re: [ansible-project] copy registered content to a file which is called from variable

2022-11-10 Thread Todd Lewis

A couple of things. First,
comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
exec_date }}.txt

has three left braces on "exec_date".

Second, mustaches (i.e. "{{" … "}}") never nest. So
    copy content="{{ compare_out.stdout }}" dest="{{ vars[ {{ 
comp_file }} ] }}"

should be

    copy content="{{ compare_out.stdout }}" dest="{{ vars[ comp_file ] }}"
Well, at least that's "dest=" without nested mustaches. Whether it's 
right or not I don't know, but it's less wrong this way.


On 11/10/22 9:16 AM, Veera wrote:

Hi,

I am trying to copy the  contents from a register output  to a file  
in the local server.
However , I have challenges in re-calling the variable filename in the 
copy command.


Correct me what I am missing. in dest="{{ vars[ {{ comp_file }} ] }}"  
or "{{ compare_out.stdout }}"  in the last lines ..



[vee@server]$ grep comp_file  vars/postcheck_vars.yml
comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
exec_date }}.txt


[vee@server]$ cat  compare_sanity.yml
- name: comparing file1 and file2
  local_action: command /usr/bin/sdiff "{{ logs_dir }}"{{ 
inventory_hostname }}-Pre-{{ exec_date }}.txt   "{{ logs_dir }}"{{ 
inventory_hostname }}-Post-{{ exec_date }}.txt

  register: compare_out
  ignore_errors: yes
  no_log: True

- name: create output  file
  local_action:
    copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{ 
comp_file }} ] }}"

  [vee@server]$


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


[ansible-project] Create VM instance from a predefined machine image

2022-11-10 Thread Valio V
Hello,
I am trying to create a VM instance from a predefined machine image using 
Ansible (ansible [core 2.13.5]) and google.cloud collection 
 (version 1.0.2).
I went through the Ansible doc for Google.Cloud and especially the 
gcp_compute_instance 
module 

 but 
could not find a way to do it.
Can you please let me know if there is any way to achieve this?

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


Re: [ansible-project] Executing multiple roles in succession

2022-11-10 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
Does the vmware-windows role need the vars defined from the vars_files? If so 
then the role itself should include them inside it's task file(s). Move the 
vars_files inside tasks/main.yml. Anything the role does after that will get 
the value of those vars definitions.

The vmware-windows role will see the values of network and vc_location that 
come into the playbook executing the role. I presume they come in as extra_vars 
from command line or ansible tower.

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

On Nov 10, 2022, at 9:54 AM, Christopher Bachmeyer 
mailto:chris.bachme...@gmail.com>> wrote:

Hi, Walter,

That is correct.  I am, the vmware-windows role is the first play and creates 
the host_group "windows" to be used as inventory in the second play.
Right now, the second role is not indented but let me give that a go this 
morning.  I'm presuming to indent the entire block starting with the hyphen
( - name:  )?

Regarding the vars_files, use import statements in the vars/main.yml of the 
first role?  I have multiple vars files under vars/ that are specific to the 
vcenters
and vlans.  Using vars_files and variables in the Ansible Tower Survey gives 
the Admins a way to customize the builds to the environment (which works well!).

Thank you!

On Thursday, November 10, 2022 at 5:23:04 AM UTC-7 
walte...@nist.gov wrote:
You need to make sure you use proper indentation. Your roles list needs to be 
indented two spaces like your vars_files.

Is it possible also that your sourcing of those the vars_files from within your 
role is overwriting the value of "windows" such that there is no inventory for 
the second play? Why do you source those vars files? The vmware-windows role 
will do that automatically.

- name: VMware-windows create role
  hosts: localhost
  gather_facts: no
  roles:
- vmware-windows

### this vars_files should not be needed

  vars_files:
- ./roles/vmware-windows/vars/{{ vc_location }}.yml
- ./roles/vmware-windows/vars/{{ network }}.yml

- name: Windows-post role
  hosts: windows
  gather_facts: no
  roles:
- windows-post


I presume that your vmware-windows role in the first play creates the host 
group called "windows" that you use as the inventory in your second play?

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

On Nov 9, 2022, at 5:30 PM, Christopher Bachmeyer  wrote:

Hey all,

I have two roles that are included in my site.yml and the goal is to execute 
the second role as soon as the first role completes.  I have added a task to 
generate a dynamic inventory in the first role that the second role can use.  I 
have a job Template in Ansible Tower and the first role executes cleanly but 
job Template completes without the second role executing.

What am I missing?

- name: VMware-windows create role
  hosts: localhost
  gather_facts: no
  roles:
  - vmware-windows

  vars_files:
- ./roles/vmware-windows/vars/{{ vc_location }}.yml
- ./roles/vmware-windows/vars/{{ network }}.yml

- name: Windows-post role
  hosts: windows
  gather_facts: no
  roles:
  - windows-post

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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/907f209c-2a3a-465e-95a3-ae82c8f27d0bn%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 
ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/37e14367-deed-4287-9a3a-f549975a7498n%40googlegroups.com

Re: [ansible-project] Executing multiple roles in succession

2022-11-10 Thread Christopher Bachmeyer
Hi, Walter, 

That is correct.  I am, the vmware-windows role is the first play and 
creates the host_group "windows" to be used as inventory in the second 
play. 
Right now, the second role is not indented but let me give that a go this 
morning.  I'm presuming to indent the entire block starting with the hyphen 
( - name:  )? 

Regarding the vars_files, use import statements in the vars/main.yml of the 
first role?  I have multiple vars files under vars/ that are specific to 
the vcenters 
and vlans.  Using vars_files and variables in the Ansible Tower Survey 
gives the Admins a way to customize the builds to the environment (which 
works well!).

Thank you! 

On Thursday, November 10, 2022 at 5:23:04 AM UTC-7 walte...@nist.gov wrote:

> You need to make sure you use proper indentation. Your roles list needs to 
> be indented two spaces like your vars_files. 
>
> Is it possible also that your sourcing of those the vars_files from within 
> your role is overwriting the value of "windows" such that there is no 
> inventory for the second play? Why do you source those vars files? The 
> vmware-windows role will do that automatically. 
>
> - name: VMware-windows create role
>   hosts: localhost   
>   gather_facts: no
>   roles:
> - vmware-windows
>
>
> ### this vars_files should not be needed
>
>
>   vars_files:
> - ./roles/vmware-windows/vars/{{ vc_location }}.yml
> - ./roles/vmware-windows/vars/{{ network }}.yml
>
>
> - name: Windows-post role
>   hosts: windows
>   gather_facts: no
>   roles:
> - windows-post
>
>
>
> I presume that your vmware-windows role in the first play creates the host 
> group called "windows" that you use as the inventory in your second play?
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services, OISM
> Mobile: 202.355.4123 <(202)%20355-4123>
>
> On Nov 9, 2022, at 5:30 PM, Christopher Bachmeyer  
> wrote:
>
> Hey all,  
>
> I have two roles that are included in my site.yml and the goal is to 
> execute the second role as soon as the first role completes.  I have added 
> a task to generate a dynamic inventory in the first role that the second 
> role can use.  I have a job Template in Ansible Tower and the first role 
> executes cleanly but job Template completes without the second role 
> executing.  
>
> What am I missing?
>
> - name: VMware-windows create role
>   hosts: localhost   
>   gather_facts: no
>   roles:
>   - vmware-windows
>
>   vars_files:
> - ./roles/vmware-windows/vars/{{ vc_location }}.yml
> - ./roles/vmware-windows/vars/{{ network }}.yml
>
> - name: Windows-post role
>   hosts: windows
>   gather_facts: no
>   roles:
>   - windows-post
>
> 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 ansible-proje...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/907f209c-2a3a-465e-95a3-ae82c8f27d0bn%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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/37e14367-deed-4287-9a3a-f549975a7498n%40googlegroups.com.


Re: [ansible-project] force file creation with template module

2022-11-10 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
I would say force: true might be used when you simply want to force every 
system to get an update regardless of whether the existing file matches the 
template. I cannot think of a case where I personally would need that, but 
someone clearly thought this might be needed so the param is there.

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

On Nov 10, 2022, at 9:10 AM, dulhaver via Ansible Project 
mailto:ansible-project@googlegroups.com>> 
wrote:

that makes sense, tx.

In which kind of situatoin is force: true then even relevant?


On 11/10/2022 2:49 PM CET 'Rowe, Walter P. (Fed)' via Ansible Project 
mailto:ansible-project@googlegroups.com>> 
wrote:


Ansible describes a state. In your case you want a file to look a certain way. 
The task will compare the output of the derived template with the existing 
file. If the existing file matches, no change is made. If the existing file 
differs or does not exist, it is overwritten or created. You don't need the 
"force" param.

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

On Nov 10, 2022, at 8:41 AM, dulhaver via Ansible Project 
mailto:ansible-project@googlegroups.com>> 
wrote:

I need to repair some templated files from a previous playbook execution

# this is a test #

- name: my template TEST - template postgres.conf
  vars:
- pg_service_name: "{{ item }}"
  ansible.builtin.template:
src: 00-ina-default.conf.j2   # 10-pg-service.conf
dest: "/home/postgres/{{ pg_service_name }}/00-ina-default.conf"
owner: postgres
group: postgres
force: true
backup: true
mode: 0600
  become: true
  loop:
- somedir

# this was a test 

this works whether dest does not exist. I want to overwrite an existing file 
though. This file possibly is or is not identical.

Can it be the force only works when the new and the old file differ?

--
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2F1890057150.554463.1668087697988%2540office.mailbox.org&data=05%7C01%7Cwalter.rowe%40nist.gov%7C858d356ab1484130c65c08dac325600b%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638036862548360143%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=ixx5qVf%2F30AZUwOxzss65mD5Wixv6L%2Bro7PBBN2pJtg%3D&reserved=0.

--
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2FE1101E15-2062-410F-92BD-3CE85D5808D2%2540nist.gov&data=05%7C01%7Cwalter.rowe%40nist.gov%7C858d356ab1484130c65c08dac325600b%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638036862548360143%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=FT2cbRNen1deUHvETb6yfrTOUpDZCx89T1iLtKjbEIo%3D&reserved=0.

--
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2F1698410404.557814.1668089444248%2540office.mailbox.org&data=05%7C01%7Cwalter.rowe%40nist.gov%7C858d356ab1484130c65c08dac325600b%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638036862548360143%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=wbYBKkKZW2L01Prwdo5%2B6A7ba68cvY0GV75z4edtIRU%3D&reserved=0.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/81F36608-1046-4DE9-AC35-9F5BFEFD8D9F%40nist.gov.


[ansible-project] copy registered content to a file which is called from variable

2022-11-10 Thread Veera
Hi,

I am trying to copy the  contents from a register output  to a file  in the 
local server.
However , I have challenges in re-calling the variable filename in the copy 
command.

Correct me what I am missing. in dest="{{ vars[ {{ comp_file }} ] }}"  or 
"{{ compare_out.stdout }}"  in the last lines ..


[vee@server]$ grep comp_file  vars/postcheck_vars.yml
comp_file: /logs/{{ exec_date }}/{{ inventory_hostname }}-compare-{{{ 
exec_date }}.txt

[vee@server]$ cat  compare_sanity.yml
- name: comparing file1 and file2 
  local_action: command /usr/bin/sdiff "{{ logs_dir }}"{{ 
inventory_hostname }}-Pre-{{ exec_date }}.txt   "{{ logs_dir }}"{{ 
inventory_hostname }}-Post-{{ exec_date }}.txt
  register: compare_out
  ignore_errors: yes
  no_log: True

- name: create output  file
  local_action:
copy   content="{{ compare_out.stdout }}" dest="{{ vars[ {{ comp_file 
}} ] }}"
  [vee@server]$


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


Re: [ansible-project] force file creation with template module

2022-11-10 Thread dulhaver via Ansible Project
that makes sense, tx. 

In which kind of situatoin is force: true then even relevant?


> On 11/10/2022 2:49 PM CET 'Rowe, Walter P. (Fed)' via Ansible Project 
>  wrote:
> 
>  
> Ansible describes a state. In your case you want a file to look a certain 
> way. The task will compare the output of the derived template with the 
> existing file. If the existing file matches, no change is made. If the 
> existing file differs or does not exist, it is overwritten or created. You 
> don't need the "force" param.
> 
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services, OISM
> Mobile: 202.355.4123
> 
> > On Nov 10, 2022, at 8:41 AM, dulhaver via Ansible Project 
> >  wrote:
> > 
> > I need to repair some templated files from a previous playbook execution
> > 
> > # this is a test #
> > 
> >  - name: my template TEST - template postgres.conf
> >vars:
> >  - pg_service_name: "{{ item }}"
> >ansible.builtin.template:
> >  src: 00-ina-default.conf.j2   # 10-pg-service.conf
> >  dest: "/home/postgres/{{ pg_service_name }}/00-ina-default.conf"
> >  owner: postgres
> >  group: postgres
> >  force: true
> >  backup: true
> >  mode: 0600
> >become: true
> >loop:
> >  - somedir
> > 
> > # this was a test 
> > 
> > this works whether dest does not exist. I want to overwrite an existing 
> > file though. This file possibly is or is not identical.
> > 
> > Can it be the force only works when the new and the old file differ?
> > 
> > -- 
> > You received this message because you are subscribed to the Google Groups 
> > "Ansible Project" group.
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to ansible-project+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit 
> > https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2F1890057150.554463.1668087697988%2540office.mailbox.org&data=05%7C01%7Cwalter.rowe%40nist.gov%7Ccb06f06277a84f7179a308dac3214f60%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638036845095155999%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=89Yh%2BMkgT0%2BB6aq8puog46RalpHHDCbMlfsGdbzYob4%3D&reserved=0.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/E1101E15-2062-410F-92BD-3CE85D5808D2%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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1698410404.557814.1668089444248%40office.mailbox.org.


Re: [ansible-project] force file creation with template module

2022-11-10 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
Ansible describes a state. In your case you want a file to look a certain way. 
The task will compare the output of the derived template with the existing 
file. If the existing file matches, no change is made. If the existing file 
differs or does not exist, it is overwritten or created. You don't need the 
"force" param.

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

> On Nov 10, 2022, at 8:41 AM, dulhaver via Ansible Project 
>  wrote:
> 
> I need to repair some templated files from a previous playbook execution
> 
> # this is a test #
> 
>  - name: my template TEST - template postgres.conf
>vars:
>  - pg_service_name: "{{ item }}"
>ansible.builtin.template:
>  src: 00-ina-default.conf.j2   # 10-pg-service.conf
>  dest: "/home/postgres/{{ pg_service_name }}/00-ina-default.conf"
>  owner: postgres
>  group: postgres
>  force: true
>  backup: true
>  mode: 0600
>become: true
>loop:
>  - somedir
> 
> # this was a test 
> 
> this works whether dest does not exist. I want to overwrite an existing file 
> though. This file possibly is or is not identical.
> 
> Can it be the force only works when the new and the old file differ?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2F1890057150.554463.1668087697988%2540office.mailbox.org&data=05%7C01%7Cwalter.rowe%40nist.gov%7Ccb06f06277a84f7179a308dac3214f60%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638036845095155999%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=89Yh%2BMkgT0%2BB6aq8puog46RalpHHDCbMlfsGdbzYob4%3D&reserved=0.

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


[ansible-project] force file creation with template module

2022-11-10 Thread dulhaver via Ansible Project
I need to repair some templated files from a previous playbook execution

# this is a test #

  - name: my template TEST - template postgres.conf
vars:
  - pg_service_name: "{{ item }}"
ansible.builtin.template:
  src: 00-ina-default.conf.j2   # 10-pg-service.conf
  dest: "/home/postgres/{{ pg_service_name }}/00-ina-default.conf"
  owner: postgres
  group: postgres
  force: true
  backup: true
  mode: 0600
become: true
loop:
  - somedir

# this was a test 

this works whether dest does not exist. I want to overwrite an existing file 
though. This file possibly is or is not identical.

Can it be the force only works when the new and the old file differ?

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


Re: [ansible-project] Executing multiple roles in succession

2022-11-10 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
You need to make sure you use proper indentation. Your roles list needs to be 
indented two spaces like your vars_files.

Is it possible also that your sourcing of those the vars_files from within your 
role is overwriting the value of "windows" such that there is no inventory for 
the second play? Why do you source those vars files? The vmware-windows role 
will do that automatically.

- name: VMware-windows create role
  hosts: localhost
  gather_facts: no
  roles:
- vmware-windows

### this vars_files should not be needed
  vars_files:
- ./roles/vmware-windows/vars/{{ vc_location }}.yml
- ./roles/vmware-windows/vars/{{ network }}.yml

- name: Windows-post role
  hosts: windows
  gather_facts: no
  roles:
- windows-post


I presume that your vmware-windows role in the first play creates the host 
group called "windows" that you use as the inventory in your second play?

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

On Nov 9, 2022, at 5:30 PM, Christopher Bachmeyer 
mailto:chris.bachme...@gmail.com>> wrote:

Hey all,

I have two roles that are included in my site.yml and the goal is to execute 
the second role as soon as the first role completes.  I have added a task to 
generate a dynamic inventory in the first role that the second role can use.  I 
have a job Template in Ansible Tower and the first role executes cleanly but 
job Template completes without the second role executing.

What am I missing?

- name: VMware-windows create role
  hosts: localhost
  gather_facts: no
  roles:
  - vmware-windows

  vars_files:
- ./roles/vmware-windows/vars/{{ vc_location }}.yml
- ./roles/vmware-windows/vars/{{ network }}.yml

- name: Windows-post role
  hosts: windows
  gather_facts: no
  roles:
  - windows-post

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 
ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/907f209c-2a3a-465e-95a3-ae82c8f27d0bn%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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/A93FA022-D086-44C2-AF96-E153DAAA6023%40nist.gov.