Re: [ansible-project] Ansible Nested Loop Question

2021-06-26 Thread Dick Visser
What I usually do in these cases is including a separate task file for
the "item" at hand.

Pseudo code:

main.yml:

- Do stuff
- include_tasks: policymap.yml
  loop: "{{ policymaps }}"
  loop_control:
loop_var: policymap

policymap.yml:

- #other task for the policymap
- include_tasks: classmap.yml
  loop: "{{ policymap.classmaps }}"
  loop_control:
loop_var: classmap


classmap.yml:
- do stuff with "{{ classmap }}"...


You can descend down into as many nested levels as needed by adding a
task file for each level.
It may seem a bit clunky at first, but I find it quite clear to
understand as it's all very explicit and the files themselves are
small.


Dick


On Sat, 26 Jun 2021 at 16:55, L. Jankok  wrote:
>
> Hi there,
>
>
> I am using the following tasks to iterate over all policy-maps (outer loop) 
> and I would also like to iterate over all class-maps into each policy-map 
> (inner-loop)
>
>
> - name: Gather all policy-maps
>
>   ansible.utils.cli_parse:
>
> command: show policy-map
>
> parser:
>
>name: ansible.netcommon.pyats
>
> set_fact: qos
>
>
> - name: Print all policy-maps
>
>   ansible.builtin.debug:
>
> msg: "no policy-map {{ item.key }}"
>
> msg: “no class-map {{ item. }}”.<— I also want to iterate 
> over the class-maps
>
>   loop: "{{ qos.policy_map|dict2items }}"
>
>
>
> After applying the dict2items the following is produced.
>
>
> ok: [cat3850] => (item={'key': 'policy3', 'value': {'class': {'example3': {}, 
> 'example4': {'set': 'dscp af12'}, 'class-default': {'set': 'ip dscp 
> af12') => {
>
> "ansible_loop_var": "item",
>
> "changed": false,
>
> "item": {
>
> "key": "policy3", <— right now 
> iterating over this works
>
> "value": {
>
> "class": {.<— I also 
> want to iterate over the class
>
> "class-default": {<— I want to 
> match only the class name
>
> "set": "ip dscp af12”.  <— I don’t want 
> to match this
>
> },
>
> "example3": {},   <— And also 
> match this class name
>
> "example4": {.<— And also 
> match this class name and so on.
>
> "set": "dscp af12”. <— I don’t want 
> to match this
>
> }
>
> }
>
> }
>
> },
>
> "msg": "no policy-map policy3”.  <— this is want I want for 
> each class name too
>
> }
>
>
> Thank you,
>
> Lucius
>
> --
> 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/CADFeZ2vXmkRXD5296Eu%2BmV8mqh%3DMWYkRPrZoh%2BNawSGddLunDw%40mail.gmail.com.



-- 
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

-- 
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/CAL8fbwMwYPWWPAeiXUjkhLVJ3HhYHrphvrX0VU%3Dfs%2B8SQwKxnQ%40mail.gmail.com.


[ansible-project] Ansible Nested Loop Question

2021-06-26 Thread L. Jankok
Hi there,


I am using the following tasks to iterate over all policy-maps (outer loop)
and I would also like to iterate over all class-maps into each policy-map
(inner-loop)


- name: Gather all policy-maps

  ansible.utils.cli_parse:

command: show policy-map

parser:

   name: ansible.netcommon.pyats

set_fact: qos


- name: Print all policy-maps

  ansible.builtin.debug:

msg: "no policy-map {{ item.key }}"

msg: “no class-map {{ item. }}”.<— I also want to
iterate over the class-maps

  loop: "{{ qos.policy_map|dict2items }}"



After applying the dict2items the following is produced.


ok: [cat3850] => (item={'key': 'policy3', 'value': {'class': {'example3':
{}, 'example4': {'set': 'dscp af12'}, 'class-default': {'set': 'ip dscp
af12') => {

"ansible_loop_var": "item",

"changed": false,

"item": {

"key": "policy3", <— right now
iterating over this works

"value": {

"class": {.<— I
also want to iterate over the class

"class-default": {<— I want to
match only the class name

"set": "ip dscp af12”.  <— I don’t want
to match this

},

"example3": {},   <— And also
match this class name

"example4": {.<— And also
match this class name and so on.

"set": "dscp af12”. <— I don’t want
to match this

}

}

}

},

"msg": "no policy-map policy3”.  <— this is want I want for
each class name too

}

Thank you,

Lucius

-- 
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/CADFeZ2vXmkRXD5296Eu%2BmV8mqh%3DMWYkRPrZoh%2BNawSGddLunDw%40mail.gmail.com.


[ansible-project] Re: Install a french version of SQLServer on an english windows server with ansible

2021-06-26 Thread 'Jean-Yves LENHOF' via Ansible Project

Le 2021-06-24 19:08, Jean-Yves LENHOF a écrit :

Hi,


I try to silently install a french version of SQLServer (this is not
my idea, it's become this is the licensed version we have) with
ansible using some code like this (I already installed MUI French lang
pack via ansible) :

- name: "Change LANG"
  win_shell: |
Set-WinUILanguageOverride -Language fr-FR

- name: "Silent Install of SQL Server 2019"
  win_shell: |
D:\SETUP.EXE
/ConfigurationFile=c:\Windows\ansible_SQLSERVER2019_EXPRESS_ConfigurationFile.ini
/SAPWD=MySuperPassw0rd /IAcceptSQLServerLicenseTerms

But it keeps saying that there's something wrong with my language...

fatal: [myserver]: FAILED! => {
"changed": true,
"cmd": "D:\\SETUP.EXE
/ConfigurationFile=c:\\Windows\\ansible_SQLSERVER2019_EXPRESS_ConfigurationFile.ini
/SAPWD=MySuperPassw0rd /IAcceptSQLServerLicenseTerms",
"delta": "0:00:00.531238",
"end": "2021-06-24 04:13:53.809159",
"msg": "non-zero return code",
"rc": 1,
"start": "2021-06-24 04:13:53.277921",
"stderr": "",
"stderr_lines": [],
"stdout": "This SQL Server setup media does not support the
language of the OS, or does not have the SQL Server English-language
version installation files.  Use the matching language-specific SQL
Server media; or install  both the language specific MUI and change
the format and system locales through the regional settings in the
control panel.\r\n\r\n\r\n\r\n",
"stdout_lines": [
"This SQL Server setup media does not support the language of
the OS, or does not have the SQL Server English-language version
installation files.  Use the matching language-specific SQL Server
media; or install  both the language specific MUI and change the
format and system locales through the regional settings in the control
panel.",
"",
"",
""
]
}

But If I'm connecting on the server the UI Lang is changed to French
(so this part seems to work) and if I run the command line on
powershell it succeed.
On Linux I would have just surcharged LANG parameter before my command
but on windows, I think this is not possible...

Is there's something on ansible which force the language to english ?
If not, is someone has an idea on what's going on...

Thanks


Regards,



Fucking off Windows !

Little followup, because that was a quite difficult one to found.
It seems that windows does'nt directly changed tue UI Language when we 
do it programmatically the configuration is pending an interactive 
connection to that user make actually the change
Here's the registry key difference I found (note the pending in the 
entry) :


Control Panel\Desktop

-"PreferredUILanguages"=hex(7):66,00,72,00,2d,00,46,00,52,00,00,00^M
+"PreferredUILanguagesPending"=hex(7):66,00,72,00,2d,00,46,00,52,00,00,00^M

I will have just to create directly this key in the hive of my ansible 
user to have the right language directly I think...



Regards,

--
Jean-Yves LENHOF
jean-y...@lenhof.eu.org

--
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/af389056acd4984745a0707bc723e670%40lenhof.eu.org.


Re: [ansible-project] How to copy a file from windows to linux

2021-06-26 Thread bulent senguler
Thanks for your answer, it opens my sight but I still do not copy content 
to file on disk. I tried copy module again but it did not work. My playbook 
and output are below.

---
- name: cp file
  hosts: all
  tasks:
  - name: copying a file
slurp: #win_copy:
  src: c:\test\b.txt #win_copy: #win_copy:
register: test   #dest: /tmp  #  src: c:\test\a.txt
  - name: dosya ici
debug:
  msg: "{{ test['content'] | b64decode }}"

  - local_action:
  module: copy
  content: "{{ test['content'] | b64decode }}"
  dest: /tmp/ba.txt


/// debug output  /

{
"msg": "adfasdf", // contains of my file 
"changed": false,
"_ansible_verbose_always": true,
"_ansible_no_log": false
}

 local_action output //
{
"changed": true,
"uid": 998,
"_ansible_delegated_vars": {
"ansible_host": "localhost"
},
"dest": "/tmp/ba.txt",
"owner": "awx",
"diff": [],
"size": 7,
"src": 
"/var/lib/awx/.ansible/tmp/ansible-tmp-1624704662.69-19-50577674979617/source",
"group": "awx",
"_ansible_no_log": false,
"checksum": "f88f94f974393a32cedc172ea3f7f4affb82f4c2",
"md5sum": "b4206b74b7563ec684336f054582605b",
"state": "file",
"gid": 995,
"secontext": "system_u:object_r:tmp_t:s0",
"mode": "0644",
"invocation": {
"module_args": {
"directory_mode": null,
"force": true,
"remote_src": null,
"dest": "/tmp/ba.txt",
"selevel": null,
"_original_basename": "tmpl88RWo",
"delimiter": null,
"regexp": null,
"owner": null,
"follow": false,
"validate": null,
"local_follow": null,
"src": 
"/var/lib/awx/.ansible/tmp/ansible-tmp-1624704662.69-19-50577674979617/source",
"group": null,
"unsafe_writes": null,
"checksum": "f88f94f974393a32cedc172ea3f7f4affb82f4c2",
"seuser": null,
"serole": null,
"content": null,
"setype": null,
"mode": null,
"attributes": null,
"backup": false
}
}
}

26 Haziran 2021 Cumartesi tarihinde saat 00:05:24 UTC+3 itibarıyla 
weiye...@gmail.com şunları yazdı:

>
> https://docs.ansible.com/ansible/latest/collections/ansible/builtin/slurp_module.html
>
> Get Outlook for iOS 
> --
> *From:* Wei-Yen Tan 
> *Sent:* Saturday, June 26, 2021 9:02:14 AM
> *To:* ansible...@googlegroups.com 
>
> *Subject:* Re: [ansible-project] How to copy a file from windows to linux
> That's not using the slurp module 
>
> Get Outlook for iOS 
> --
> *From:* ansible...@googlegroups.com  on 
> behalf of bulent senguler 
> *Sent:* Saturday, June 26, 2021 8:57:56 AM
> *To:* Ansible Project 
> *Subject:* Re: [ansible-project] How to copy a file from windows to linux 
>  
> - name: copy file from windows to tower 
>   copy_win:
> src : c:\tmp\b.txt
>  dest: /tmp
>   remote_src: yes
>
>
> output :
>
> {
> "src": "c:\\test\\b.txt",
> "_ansible_no_log": false,
> "dest": "/tmp",
> "checksum": "f88f94f974393a32cedc172ea3f7f4affb82f4c2",
> "changed": true,
> "original_basename": "b.txt",
> "operation": "file_copy",
> "size": 7
> }
>
> the job finished successfuly, the file does not exist in tmp directory
>
> 25 Haziran 2021 Cuma tarihinde saat 23:28:52 UTC+3 itibarıyla 
> weiye...@gmail.com şunları yazdı:
>
> What do yoy mean. Is it doing the same thing? Can you please share play 
> book and task?
>
> Get Outlook for iOS 
> --
> *From:* ansible...@googlegroups.com  on 
> behalf of bulent senguler 
> *Sent:* Saturday, June 26, 2021 8:25:00 AM
> *To:* Ansible Project 
> *Subject:* Re: [ansible-project] How to copy a file from windows to linux 
>  
> Actually, as a same result.
>
> 25 Haziran 2021 Cuma tarihinde saat 22:42:56 UTC+3 itibarıyla 
> weiye...@gmail.com şunları yazdı:
>
> Slurp to ansible controller then copy to linux 
>
> Get Outlook for iOS 
> --
> *From:* ansible...@googlegroups.com  on 
> behalf of bulent senguler 
> *Sent:* Saturday, June 26, 2021 7:41:26 AM
> *To:* Ansible Project 
> *Subject:* [ansible-project] How to copy a file from windows to linux 
>  
> Hi all, 
> I want to copy a file from windows to linux but I cannot do that. I trıed 
> win_copy module and remote_src=yes and job was success but the file did not 
> exist on target machine.  Where I am wrong. Thanks for helps.
>
> -- 
> 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 

Re: [ansible-project] help debugging calling import_playbook

2021-06-26 Thread need abettername
Perhpas I have a misunderstanding here

When you say " no connection is involved"

If I'm right it is possible to ssh from a server to itself - shown by a new
shell and the ability to exit back to the previous shell - or am I mistaken
and it's somehow ignoring that

Is this not what ansible is doing if you run a playbook on the same server
(without delegate_to or local connection)?

That would seem to be what's happening from the ssh output (broken pipe)
but I may be completely turned around in my understanding here (?)

On Fri, 25 Jun 2021 at 22:19, needabettername  wrote:

> Thanks Brian
>
> Not quite sure I understand, it's the output I'm trying to get (more of)
> to understand why it's failing.
>
> In case it helps at all
>
>
> Here's the play 2 created that it fails on. This is fine to run directly
> through ansible-playbook, just not through that play1
>
> - hosts: nott
>   become: yes
>   vars_files:
> - /$LINUX_PLAYBOOKS/paperless/mont_nott_vars.yml
>   tasks:
>   roles:
> # - geerlingguy.postgresql
> - paperless-ng
> # - geerlingguy.nginx
>
>
> Here's the section of play 1
>   # post_tasks:
>   - name: run the play - $LINUX_PLAYBOOKS/paperless/{{play_filename}}
> import_playbook: $LINUX_PLAYBOOKS/paperless/{{play_filename}}
> register: playoutput
> ignore_errors: yes
> # delegate_to: 127.0.0.1
> become: yes
> # debugger: on_failed
>
>   - name: get debug output
> debug:
>   var: playoutput
>
> Does that help, or is there something else I can run to get more detail
> from that mysterious " See stdout/stderr for the exact error"
> That's what the debug var playoutput should provide isn't it ??
>
> On Friday, 25 June 2021 at 15:18:51 UTC+1 Brian Coca wrote:
>
>> The import would not fail with connection issues, no connection is
>> involved, what is failing is a task, but you are not providing enough
>> output to determine which task it is.
>>
>> --
>> --
>> Brian Coca
>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/iTafYTAtEIA/unsubscribe.
> To unsubscribe from this group and all its topics, 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/49307f93-581d-469a-aaf9-cfefc0138466n%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/CAO-qrLaVRu%3DjPDGCUSivQotouYUFheTWhJTn8XOO0hz%3DuS9Rig%40mail.gmail.com.


[ansible-project] Re: How to get the hostname into jinja file

2021-06-26 Thread Avinash Krishnan
Hi,

Are you looking to set the url on each server during playbook execution ? 
You can use magic variable  inventory_hostname  to dynamically get hostname 
during play execution.

*teaserverurl: "http://{{ inventory_hostname }}:8777/tea"*


On Friday, June 25, 2021 at 3:34:08 PM UTC+5:30 shaikabdu...@gmail.com 
wrote:

> Hi Folks,
>
> Thank you for reading this.
>
> My expectation is to get the hostname from the inventory file, please help 
> how to get this.
>
>
> Jinjafile :
>
> teaserverurl: "http://{{tibcoteahost}}:8777/tea;
>
>
> vars file :
> tibco_tea_group: 
> "{{ groups['tibco_tea'] | default(ansible_play_hosts) | sort }}"
> tibcoteahost: >
>"{% for server in tibco_tea_group -%}
>{{ hostvars.get(server).ansible_all_ipv4_addresses }}
>{% endfor %}"
>
> inventory file:
> ---
> all:
>   vars:
> ansible_connection: ssh
> ansible_user: pibco
>   children:
> tibco:
>   vars:
> tibco_user: pibco
> tibco_group: pibgrp
> ansible_ssh_pass: Maddy1600
>   hosts:
> tomlap01195.:
> tibco_tea:
>   vars:
> tibco_user: pibco
> tibco_group: pibgrp
> ansible_ssh_pass: Maddy1600
>   hosts:
> tomlap04090.corp:
> local:
>   hosts:
> localhost:
>   ansible_connection: local
>

-- 
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/f799e66d-0c18-447b-846a-b8760f94da52n%40googlegroups.com.