[ansible-project] Ansible creating a host on zabbix with playbook

2019-08-15 Thread Ari Prince
Hi guys, am testing the zabbix official playbook from ansible site.
I've changed all the values with mine, but when run it I get "Failed to connect 
to Zabbix server: urllib2. URLError - Not Found"

Any ideas how fix 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/79d7f414-8f8b-4ba2-a604-246ae0ee5b92%40googlegroups.com.


[ansible-project] Ansible 2.8.1: Multiline debug not working with debug output filter

2019-08-15 Thread Andrew Hodgson
Hi all,

I am using Ansible 2.8.1 and want to create a multiline debug output at the end 
of a play run:

https://docs.ansible.com/ansible/latest/modules/debug_module.html

Suggests this is possible, I am trying the following:

- name: Give cluster information
  debug:
msg:
  - "Information about your deployed AKS cluster:"
  - "Cluster Name   : {{ aks_name }}"
[...]

This seems to work as expected by default, however if we specify the debug 
output filter as an environment variable:

ANSIBLE_STDOUT_CALLBACK=debug

Then the output is not split up onto separate lines, and the information is 
represented in one large block of text in one line.  Has anyone seen this 
before?

Thanks.
Andrew.

-- 
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/DB6PR0801MB1880117CDED56650E5806EAAAFAC0%40DB6PR0801MB1880.eurprd08.prod.outlook.com.


Re: [ansible-project] How to use Ansible with clients that have dynamic (DHCP) IPs?

2019-08-15 Thread Matt Fahrner
Mean to respond to this earlier. Thank you - yes VPN is a possibility here 
as well.

Thanks again.

On Saturday, July 27, 2019 at 6:37:07 PM UTC-4, J wrote:
>
> You also could use an automatc VPN client and the corresponding IP; this 
> also works for DHCP Clients that are leaving your network. 
> (relevant for homeoffices etc). 
>
> On 19-07-26 16:02:02, Matt Fahrner wrote: 
> > That's certainly a possibility, though it starts to be a little 
> impractical 
> > as you start to size out. Still, something to think about - thanks! 
> > 
> > On Friday, July 26, 2019 at 6:57:29 PM UTC-4, Jonathan Lozada De La 
> Matta 
> > wrote: 
> > > 
> > > you can potentially create or search for a dynamic inventory script 
> that 
> > > can pull your addresses from whatever provides dhcp. You must have a 
> list 
> > > somewhere so check how you can pull that. You can also do a static 
> > > inventory and do ranges. So for example, if your range of windows are 
> in 
> > > 192.168.50.1-192.168.50.200. Worse case scenario you can use an 
> inventory 
> > > that has all the ranges of IP and do tasks based on facts.  There's 
> option 
> > > but, you have to find what works for you. 
> > > 
> > > Jonathan Lozada De La Matta on mobile 
> > > 
> > > -- 
> > > *From:* ansible...@googlegroups.com  on behalf of Matt 
> > > Fahrner > 
> > > *Sent:* Friday, July 26, 2019 6:48 PM 
> > > *To:* Ansible Project 
> > > *Subject:* Re: [ansible-project] How to use Ansible with clients that 
> > > have dynamic (DHCP) IPs? 
> > > 
> > > Thanks Dick - I get your point. That said, not that this is the 
> direction 
> > > I want to go at the moment, Puppet does have agents that slightly 
> simplify 
> > > this particular part of the problem. 
> > > 
> > > Anyway, good to have confirmation that DDNS is on the right track. 
> > > 
> > > Thanks again! 
> > > 
> > > On Friday, July 26, 2019 at 6:26:47 PM UTC-4, Dick Visser wrote: 
> > >> 
> > >> That is a general issue with hosts that have dynamic addresses. 
> > >> DDNS is one example of how to address that - this in fact is 'a minor 
> > >> agent' as you call it. 
> > >> There is no single solution, and it is not specific to ansible. 
> > >> 
> > >> Dick 
> > >> 
> > >> On Fri, 26 Jul 2019 at 23:47, Matt Fahrner  wrote: 
> > >> > 
> > >> > Since Ansible is clientless, if say you were trying to manage 
> Windows 
> > >> or Mac laptops that didn't have fixed IPs (eg: DHCP clients), how do 
> you 
> > >> solve this scenario? 
> > >> > 
> > >> > Do you use Dynamic DNS (DDNS)? 
> > >> > 
> > >> > Have others solved this - seems almost like you need a minor agent 
> for 
> > >> registration but... 
> > >> > 
> > >> > Thanks 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 ansible...@googlegroups.com. 
> > >> > To view this discussion on the web visit 
> > >> 
> https://groups.google.com/d/msgid/ansible-project/ff690312-b33e-45b0-8162-49b81ae30ebe%40googlegroups.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...@googlegroups.com . 
> > > To view this discussion on the web visit 
> > > 
> https://groups.google.com/d/msgid/ansible-project/6e85122a-7c68-4bce-a985-230de680350b%40googlegroups.com
>  
> > > <
> https://groups.google.com/d/msgid/ansible-project/6e85122a-7c68-4bce-a985-230de680350b%40googlegroups.com?utm_medium=email_source=footer>
>  
>
> > > . 
> > > 
> > 
> > -- 
> > 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...@googlegroups.com . 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/e2ed8737-e3a0-4566-8373-ed1a3198fb08%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/92eb1b85-31ab-43a0-9d5b-50045a227e7b%40googlegroups.com.


[ansible-project] Can inventory plugin "constructed" create a groups based on ansible_facts

2019-08-15 Thread Михаил Политаев
Hello community!

A have plenty of EC2 servers in AWS and want to categorize them based on 
gathered from ansible_facts (by module setup), for example have group 
"CentOS" where ansible_facts['distribution'] == 'CentOS' and so on. But 
having file "inventory/constructed.yml":

plugin: constructed
strict: False
keyed_groups:
  # this creates a group per distro (distro_CentOS, distro_Debian) and 
assigns the hosts that have matching values to it,
  # using the default separator "_"
  - prefix: distro
key: ansible_distribution

I don't see this group "distro_CentOS" in output command "ansible-inventory 
--graph".

Also this plugin enabled in ansible.cfg:

[inventory]
# enable inventory plugins, default: 'host_list', 'script', 'auto', 'yaml', 
'ini', 'toml'
enable_plugins = host_list, ini, aws_ec2, *constructed*

How I can sort instances EC2 based on gathered ansible's facts, avoiding 
tag each 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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5bb8ca47-0d6c-4657-993e-edfdc24592d6%40googlegroups.com.


Re: [ansible-project] ansible find.py seems to fail on NFS drives with certain mount options

2019-08-15 Thread Larry Kyrala
Thanks Kai, I tried and narrowed down the following:

# strace on isdir


$ diff nfs_{bad,good}.log
1,2c1,2
< user2 ~> sudo -H strace -f python -c 'import os; print 
os.path.isdir("nfsdir")'
< execve("/usr/bin/python", ["python", "-c", "import os; print 
os.path.isdir(\""...], [/* 17 vars */]) = 0
---
> user1 ~$ sudo -H strace -f python -c 'import os; print 
os.path.isdir("nfsdir")'
> execve("/usr/bin/python", ["python", "-c", "import os; print 
os.path.isdir(\""...], [/* 14 vars */]) = 0
762,765c762,765
< stat("nfsdir", 0xADDRESS) = -1 EACCES (Permission denied)
< fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
< write(1, "False\n", 6False
< )  = 6
---
> stat("nfsdir", {st_mode=S_IFDIR|0755, st_size=4, ...}) = 0
> fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 7), ...}) = 0
> write(1, "True\n", 5True
> )   = 5


So isdir is failing on the bad system, specifically a stat call is failing.

And running stat directly confirms this:

# stats on dirs


$ diff {bad,good}_stat.log
1,2c1,9
< user2 ~> sudo stat nfsdir
< stat: cannot stat '/home/user2/nfsdir': Permission denied
---
> user1 ~$ sudo stat nfsdir
>   File: nfsdir
>   Size: 4   Blocks: 3  IO Block: 8192   directory
> Device: 36h/54d Inode: 384033  Links: 2
> Access: (0755/drwxr-xr-x)  Uid: ( 5954/ user1)   Gid: (  101/   users)
> Access: 2019-06-06 14:14:23.025878969 -0400
> Modify: 2019-08-14 15:37:43.576408706 -0400
> Change: 2019-08-14 15:37:43.576408706 -0400
>  Birth: -


So the "bad" machine is setup to not allow sudo to be able to see the nfs 
mount for the network user "user2".




On Wednesday, August 14, 2019 at 4:16:53 PM UTC-4, Kai Stian Olstad wrote:
>
> On 14.08.2019 21:12, Larry Kyrala wrote: 
> > "matched": 0, 
> > "msg": "deployments/ was skipped as it does not seem to be a valid 
> > directory or it cannot be accessed\n" 
> > } 
> > 
> > 
> > 
> > 
> > # script that is failing - deploy/main.yml: 
> > 
> > 
> > - name: find deployments 
> >   find: 
> > paths: deployments/ 
> > patterns: "*.json" 
> > excludes: "sample_deployment.json" 
> >   register: files_matched 
> > 
> > 
> > 
> > 
> > # directory permissions from within the VM: 
>
> It can be a few possibilities, since you are using relative path it 
> might not search in correct paths. 
> The easiest way to see what happens might be strace on the failing 
> machine 
>
>strace -f ansible-playbook deploy.yml --ask-become-pass 2>&1 | grep 
> deployments 
>
> This will show every system call against deployments 
>
>
> The find module stops after it test deployments/ is a directory with 
> os.path.isdir, you can test it with this code and is should print True, 
> since you are using become you should run this with sudo. 
>
>sudo -H python -c 'import os; print os.path.isdir("deployments/")' 
>
>
> -- 
> Kai Stian Olstad 
>

-- 
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/38f04648-0b47-4f41-8741-078378593b77%40googlegroups.com.


[ansible-project] Loop until k8s (lookup/query) module returns a valid value

2019-08-15 Thread Thms Hmm
Ansible Version: 2.8.1

Hi,

I'm trying to get the status of a Kubernetes StatefulSet and wait till it 
has a specific value.

The task looks like this:
- set_fact:
myVar: "{{ query('k8s', host='myhost.local', ... kind='StatefulSet', 
label_selector='app=test') }}"
  retries: 5
  delay: 30
  until: "myVar[0]['status']['readyReplicas']|int == 3"

The problem I have is, the loop is executed but the "myVar" variable is 
never updated and has it's initial value.

Has anyone seen or tried this? Is there an alternative?

Thomas

-- 
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/4019ecaa-eebc-4d39-b03a-d1e202446967%40googlegroups.com.


[ansible-project] Json output

2019-08-15 Thread vinoth kumar


Hi Folks,
I need your help here, how can i get all hostnames (marked) to print. when 
i try msg: "{{results.json.actions[0].system.hostname}}" and msg: 
"{{results.json.actions[1].system.hostname}}" it prints me the two hosts, 
but i need all hosts availble in single msg -- tried this --msg: 
"{{results.json.actions[*].system.hostname}}" not working. i am still 
confused in getting info from json can some one give me good link to learn 
about this.

I used URI module to fetch this info:


ok: [localhost] => {
"msg": {
"cache_control": "no-cache",
"changed": false,
"connection": "close",
"content_length": "2220",
"content_type": "application/json; charset=utf-8",
"cookies": {
"a5442528c5a688d4fb7fca696f6ac395": 
"d19de2f36ad8eea0b2f80509777960b8"
},
"cookies_string": 
"a5442528c5a688d4fb7fca696f6ac395=d19de2f36ad8eea0b2f80509777960b8",
"date": "Thu, 15 Aug 2019 15:12:22 GMT",
"etag": "\"8ac-julM1vkItyH51OY7TzLhAe1ha1o\"",
"failed": false,
"json": {
"actions": [
{
"current_report": {
"details": {},
"id": 1409219514
},
"done": false,
"id": 760010,
"maintenance_id": 44153,
"rule": {
"ansible": true,
"ansible_fix": true,
"ansible_mitigation": false,
"category": "Security",
"description": "Kernel with loaded modules 
vulnerable to denial of service via Bluetooth stack 
(CVE-2017-1000251/Blueborne)",
"description_html": "Kernel with loaded modules 
vulnerable to denial of service via Bluetooth stack 
(CVE-2017-1000251/Blueborne)\n",
"id": 
"CVE_2017_1000251_kernel_blueborne|KERNEL_CVE_2017_1000251_LOADED_DOS",
"node_id": "3177271",
"reboot_required": true,
"rec_impact": 3,
"rec_likelihood": 4,
"severity": "ERROR"
},
"system": {
"display_name": null,
"hostname": "",
"isCheckingIn": true,
"last_check_in": "2019-08-15T00:20:08.000Z",
"remote_branch": 
"98d1a60f-f62c-4039-a604-19bee8adc0b0",
"remote_leaf": 
"7636906c-a11b-4988-ade2-5f43d233bb75",
"system_id": "765884e3-381b-45f4-8780-2377c7bf1a35",
"system_type_id": 105,
"toString": ""
}
},
{
"current_report": {
"details": {},
"id": 1409403783
},
"done": false,
"id": 760011,
"maintenance_id": 44153,
"rule": {
"ansible": true,
"ansible_fix": true,
"ansible_mitigation": false,
"category": "Security",
"description": "Kernel with loaded modules 
vulnerable to denial of service via Bluetooth stack 
(CVE-2017-1000251/Blueborne)",
"description_html": "Kernel with loaded modules 
vulnerable to denial of service via Bluetooth stack 
(CVE-2017-1000251/Blueborne)\n",
"id": 
"CVE_2017_1000251_kernel_blueborne|KERNEL_CVE_2017_1000251_LOADED_DOS",
"node_id": "3177271",
"reboot_required": true,
"rec_impact": 3,
"rec_likelihood": 4,
"severity": "ERROR"
},
"system": {
"display_name": null,
"hostname": "***",
"isCheckingIn": true,
"last_check_in": "2019-08-15T03:44:41.000Z",
"remote_branch": 
"98d1a60f-f62c-4039-a604-19bee8adc0b0",
"remote_leaf": 
"97dd-9bd9-4a1a-b1a0-a92a95bd2663",
"system_id": "9b72e8d7-4b86-4cf6-9bae-688a04a5a2b3",
"system_type_id": 105,
"toString": ""
}
}
],
"allow_reboot": true,
"created_by": "cert-system-658772",
"description": null,
"end": null,
"hidden": false,
"maintenance_id": 44153,
"name": "***",

Re: [ansible-project] ansible find.py seems to fail on NFS drives with certain mount options

2019-08-15 Thread Larry Kyrala
The other user's home directory didn't have execute privileges. 

Thanks for your help and patience!

On Thursday, August 15, 2019 at 2:08:21 PM UTC-4, Larry Kyrala wrote:
>
> Thanks Kai, I tried and narrowed down the following:
>
> # strace on isdir
>
>
> $ diff nfs_{bad,good}.log
> 1,2c1,2
> < user2 ~> sudo -H strace -f python -c 'import os; print 
> os.path.isdir("nfsdir")'
> < execve("/usr/bin/python", ["python", "-c", "import os; print 
> os.path.isdir(\""...], [/* 17 vars */]) = 0
> ---
> > user1 ~$ sudo -H strace -f python -c 'import os; print 
> os.path.isdir("nfsdir")'
> > execve("/usr/bin/python", ["python", "-c", "import os; print 
> os.path.isdir(\""...], [/* 14 vars */]) = 0
> 762,765c762,765
> < stat("nfsdir", 0xADDRESS) = -1 EACCES (Permission denied)
> < fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
> < write(1, "False\n", 6False
> < )  = 6
> ---
> > stat("nfsdir", {st_mode=S_IFDIR|0755, st_size=4, ...}) = 0
> > fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 7), ...}) = 0
> > write(1, "True\n", 5True
> > )   = 5
>
>
> So isdir is failing on the bad system, specifically a stat call is failing.
>
> And running stat directly confirms this:
>
> # stats on dirs
>
>
> $ diff {bad,good}_stat.log
> 1,2c1,9
> < user2 ~> sudo stat nfsdir
> < stat: cannot stat '/home/user2/nfsdir': Permission denied
> ---
> > user1 ~$ sudo stat nfsdir
> >   File: nfsdir
> >   Size: 4   Blocks: 3  IO Block: 8192   directory
> > Device: 36h/54d Inode: 384033  Links: 2
> > Access: (0755/drwxr-xr-x)  Uid: ( 5954/ user1)   Gid: (  101/   users)
> > Access: 2019-06-06 14:14:23.025878969 -0400
> > Modify: 2019-08-14 15:37:43.576408706 -0400
> > Change: 2019-08-14 15:37:43.576408706 -0400
> >  Birth: -
>
>
> So the "bad" machine is setup to not allow sudo to be able to see the nfs 
> mount for the network user "user2".
>
>
>
>
> On Wednesday, August 14, 2019 at 4:16:53 PM UTC-4, Kai Stian Olstad wrote:
>>
>> On 14.08.2019 21:12, Larry Kyrala wrote: 
>> > "matched": 0, 
>> > "msg": "deployments/ was skipped as it does not seem to be a valid 
>> > directory or it cannot be accessed\n" 
>> > } 
>> > 
>> > 
>> > 
>> > 
>> > # script that is failing - deploy/main.yml: 
>> > 
>> > 
>> > - name: find deployments 
>> >   find: 
>> > paths: deployments/ 
>> > patterns: "*.json" 
>> > excludes: "sample_deployment.json" 
>> >   register: files_matched 
>> > 
>> > 
>> > 
>> > 
>> > # directory permissions from within the VM: 
>>
>> It can be a few possibilities, since you are using relative path it 
>> might not search in correct paths. 
>> The easiest way to see what happens might be strace on the failing 
>> machine 
>>
>>strace -f ansible-playbook deploy.yml --ask-become-pass 2>&1 | grep 
>> deployments 
>>
>> This will show every system call against deployments 
>>
>>
>> The find module stops after it test deployments/ is a directory with 
>> os.path.isdir, you can test it with this code and is should print True, 
>> since you are using become you should run this with sudo. 
>>
>>sudo -H python -c 'import os; print os.path.isdir("deployments/")' 
>>
>>
>> -- 
>> Kai Stian Olstad 
>>
>

-- 
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/39040748-fb12-4d05-b064-58828c5f80ae%40googlegroups.com.


Re: [ansible-project] Difficulty differencing list with integers vs list with strings.

2019-08-15 Thread gaurav thosani
Auralan,

Wondering if jinja2 typecasting could be attempted for your use case
Reference:
https://stackoverflow.com/questions/39938323/jinja-convert-string-to-integer?rq=1

Gaurav Thosani



On Thu, Aug 15, 2019 at 3:09 PM Auralan  wrote:

> Hi everyone,
>
> I've been struggling to get the difference between 2 lists in Ansible.
> List 1 contains numbers as integers. List 2 contains numbers as strings.
> These obviously cannot be filtered with difference().
>
> Does anyone know a workaround? Or a point where I can make a change in my
> parsing to remediate this difference?
> We are using Ansible 2.7.10. Upgrading is an option if needed. My setup
> is below.  Thank you for your time!
>
>
>
> List 1 comes from parsing a JSON document.
>
>
>   - name: "Create list from JSON source."
> set_fact:
>   cmdb_list: "{{ cmdb_call.json.results | map(attribute='vid') | list
> }}"
>
> # Debug of cmdb_list. Output shortened for readability.
> ok: [localhost] => {
> "msg": [
> [
> 2141,
> 2142,
> 2143
> ]
> ]
> }
>
>
>
> List 2 comes from parsing a XML document in 2 steps.
>
>   - name: "Create list from XML source. Step 1."
> xml:
>   xmlstring: "{{ device_call.ansible_facts.ansible_net_config }}"
>   xpath: //vlan-id
>   content: "text"
> register: device_call_filtered
>
> # Debug of device_call_filtered. Output of matches and xmlstring keys
> shortened for readability.
> ok: [some_switch] => {
> "msg": [
> {
> "actions": {
> "namespaces": {},
> "state": "present",
> "xpath": "//vlan-id"
> },
> "changed": false,
> "count": 18,
> "failed": false,
> "matches": [
> {
> "vlan-id": "2141"
> },
> {
> "vlan-id": "2056"
> }
> ],
> "msg": 18,
> "xmlstring": "\\n
> \\n \\n \\n some_vlan\\n
> 2141\\n \\n \\n "
> }
> ]
> }
>
>   - name: "Create list of configured VLANs per Device."
> set_fact:
>   device_list: "{{ device_call_filtered.matches |
> map(attribute='vlan-id') | list }}"
> delegate_facts: true
>
> # Debug of device_list. Output shortened for readability.
> ok: [some_switch] => {
> "msg": [
> [
> "2141",
> "2056"
> ]
> ]
> }
>
>   - name: "Get difference."
> set_fact:
>   difference_list: "{{ cmdb_list | difference(device_list) }}"
>
> ^ So that's not going to work in this state.
>
> --
> 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/da41df3e-93d3-4745-a98b-4acd7d182cc2%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/CAGvJ0CVR5u4rs%3DgiNtBW4rGUyMbzLHcaBhgpFPAP8TLe_4Fiig%40mail.gmail.com.


[ansible-project] Difficulty differencing list with integers vs list with strings.

2019-08-15 Thread Auralan
Hi everyone,

I've been struggling to get the difference between 2 lists in Ansible. 
List 1 contains numbers as integers. List 2 contains numbers as strings.
These obviously cannot be filtered with difference(). 

Does anyone know a workaround? Or a point where I can make a change in my 
parsing to remediate this difference?
We are using Ansible 2.7.10. Upgrading is an option if needed. My setup is 
below.  Thank you for your time!



List 1 comes from parsing a JSON document.


  - name: "Create list from JSON source."
set_fact:
  cmdb_list: "{{ cmdb_call.json.results | map(attribute='vid') | list 
}}"

# Debug of cmdb_list. Output shortened for readability.
ok: [localhost] => {
"msg": [
[
2141, 
2142, 
2143
]
]
}



List 2 comes from parsing a XML document in 2 steps.

  - name: "Create list from XML source. Step 1."
xml:
  xmlstring: "{{ device_call.ansible_facts.ansible_net_config }}"
  xpath: //vlan-id
  content: "text"
register: device_call_filtered

# Debug of device_call_filtered. Output of matches and xmlstring keys 
shortened for readability.
ok: [some_switch] => {
"msg": [
{
"actions": {
"namespaces": {}, 
"state": "present", 
"xpath": "//vlan-id"
}, 
"changed": false, 
"count": 18, 
"failed": false, 
"matches": [
{
"vlan-id": "2141"
}, 
{
"vlan-id": "2056"
}
], 
"msg": 18, 
"xmlstring": "\\n 
\\n \\n \\n some_vlan\\n 
2141\\n \\n \\n "
}
]
}

  - name: "Create list of configured VLANs per Device."
set_fact:   
  device_list: "{{ device_call_filtered.matches | 
map(attribute='vlan-id') | list }}"
delegate_facts: true

# Debug of device_list. Output shortened for readability.
ok: [some_switch] => {
"msg": [
[
"2141", 
"2056"
]
]
}

  - name: "Get difference."
set_fact:
  difference_list: "{{ cmdb_list | difference(device_list) }}"
  
^ So that's not going to work in this state.

-- 
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/da41df3e-93d3-4745-a98b-4acd7d182cc2%40googlegroups.com.


[ansible-project] Re: Using the magic variable groups

2019-08-15 Thread Harrymosco
Thanks Kai Stian,

Absolutely what I want. Fantastic!!

All I am doing now is use "--extra-vars" and assign any   I 
want to configure to the variable, and that's it.
The code does not need to be modified anymore for different s.

Appreciated!!

-Harrymosco.  

On Friday, August 9, 2019 at 10:11:41 AM UTC-5, Harrymosco wrote:
>
> Can I use a variable to insert inventory group when using groups; e.g.  
> groups['$groupname']?
>

-- 
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/7dc6745d-18b7-411c-aef4-35eebe6d999e%40googlegroups.com.


[ansible-project] Re: Difficulty differencing list with integers vs list with strings.

2019-08-15 Thread Zolvaring
Would something like this syntax help?


set_fact:
  difference_list: >-
{{ numbers_as_integers |
difference(numbers_as_strings |
map(attribute='whatever_attribute_you_may_need') |
map('int') |
list }}

^ What that should do for the list of numbers as strings, is filter dicts 
into a pure list based on attribute (not clear if you need this or not, if 
you have a pure list of integers as strings you can remove that part 
obviously), the second map will apply the int filter to all members of your 
list, and then finally make it iterable with list. I was only able to test 
this briefly but it seemed to work for me if I understand what you're 
trying to do.

On Thursday, August 15, 2019 at 3:09:03 PM UTC-7, Auralan wrote:
>
> Hi everyone,
>
> I've been struggling to get the difference between 2 lists in Ansible. 
> List 1 contains numbers as integers. List 2 contains numbers as strings.
> These obviously cannot be filtered with difference(). 
>
> Does anyone know a workaround? Or a point where I can make a change in my 
> parsing to remediate this difference?
> We are using Ansible 2.7.10. Upgrading is an option if needed. My setup 
> is below.  Thank you for your time!
>
>
>
> List 1 comes from parsing a JSON document.
>
>
>   - name: "Create list from JSON source."
> set_fact:
>   cmdb_list: "{{ cmdb_call.json.results | map(attribute='vid') | list 
> }}"
>
> # Debug of cmdb_list. Output shortened for readability.
> ok: [localhost] => {
> "msg": [
> [
> 2141, 
> 2142, 
> 2143
> ]
> ]
> }
>
>
>
> List 2 comes from parsing a XML document in 2 steps.
>
>   - name: "Create list from XML source. Step 1."
> xml:
>   xmlstring: "{{ device_call.ansible_facts.ansible_net_config }}"
>   xpath: //vlan-id
>   content: "text"
> register: device_call_filtered
>
> # Debug of device_call_filtered. Output of matches and xmlstring keys 
> shortened for readability.
> ok: [some_switch] => {
> "msg": [
> {
> "actions": {
> "namespaces": {}, 
> "state": "present", 
> "xpath": "//vlan-id"
> }, 
> "changed": false, 
> "count": 18, 
> "failed": false, 
> "matches": [
> {
> "vlan-id": "2141"
> }, 
> {
> "vlan-id": "2056"
> }
> ], 
> "msg": 18, 
> "xmlstring": "\\n 
> \\n \\n \\n some_vlan\\n 
> 2141\\n \\n \\n "
> }
> ]
> }
>
>   - name: "Create list of configured VLANs per Device."
> set_fact:   
>   device_list: "{{ device_call_filtered.matches | 
> map(attribute='vlan-id') | list }}"
> delegate_facts: true
> 
> # Debug of device_list. Output shortened for readability.
> ok: [some_switch] => {
> "msg": [
> [
> "2141", 
> "2056"
> ]
> ]
> }
>
>   - name: "Get difference."
> set_fact:
>   difference_list: "{{ cmdb_list | difference(device_list) }}"
>   
> ^ So that's not going to work in this state.
>
>

-- 
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/d6154dbf-e628-4547-a968-0f69bff72fbd%40googlegroups.com.


[ansible-project] Re: Difficulty differencing list with integers vs list with strings.

2019-08-15 Thread Zolvaring
On closer examination I dropped a parenthesis entering this in, so for 
clarity:

difference_list: >-
{{ numbers_as_integers |
difference(numbers_as_strings |
map(attribute='whatever_attribute_you_may_need') |
map('int') |
list) }}

On Thursday, August 15, 2019 at 7:03:50 PM UTC-7, Zolvaring wrote:
>
> Would something like this syntax help?
>
>
> set_fact:
>   difference_list: >-
> {{ numbers_as_integers |
> difference(numbers_as_strings |
> map(attribute='whatever_attribute_you_may_need') |
> map('int') |
> list }}
>
> ^ What that should do for the list of numbers as strings, is filter dicts 
> into a pure list based on attribute (not clear if you need this or not, if 
> you have a pure list of integers as strings you can remove that part 
> obviously), the second map will apply the int filter to all members of your 
> list, and then finally make it iterable with list. I was only able to test 
> this briefly but it seemed to work for me if I understand what you're 
> trying to do.
>
> On Thursday, August 15, 2019 at 3:09:03 PM UTC-7, Auralan wrote:
>>
>> Hi everyone,
>>
>> I've been struggling to get the difference between 2 lists in Ansible. 
>> List 1 contains numbers as integers. List 2 contains numbers as strings.
>> These obviously cannot be filtered with difference(). 
>>
>> Does anyone know a workaround? Or a point where I can make a change in my 
>> parsing to remediate this difference?
>> We are using Ansible 2.7.10. Upgrading is an option if needed. My setup 
>> is below.  Thank you for your time!
>>
>>
>>
>> List 1 comes from parsing a JSON document.
>>
>>
>>   - name: "Create list from JSON source."
>> set_fact:
>>   cmdb_list: "{{ cmdb_call.json.results | map(attribute='vid') | list 
>> }}"
>>
>> # Debug of cmdb_list. Output shortened for readability.
>> ok: [localhost] => {
>> "msg": [
>> [
>> 2141, 
>> 2142, 
>> 2143
>> ]
>> ]
>> }
>>
>>
>>
>> List 2 comes from parsing a XML document in 2 steps.
>>
>>   - name: "Create list from XML source. Step 1."
>> xml:
>>   xmlstring: "{{ device_call.ansible_facts.ansible_net_config }}"
>>   xpath: //vlan-id
>>   content: "text"
>> register: device_call_filtered
>>
>> # Debug of device_call_filtered. Output of matches and xmlstring keys 
>> shortened for readability.
>> ok: [some_switch] => {
>> "msg": [
>> {
>> "actions": {
>> "namespaces": {}, 
>> "state": "present", 
>> "xpath": "//vlan-id"
>> }, 
>> "changed": false, 
>> "count": 18, 
>> "failed": false, 
>> "matches": [
>> {
>> "vlan-id": "2141"
>> }, 
>> {
>> "vlan-id": "2056"
>> }
>> ], 
>> "msg": 18, 
>> "xmlstring": "\\n 
>> \\n \\n \\n some_vlan\\n 
>> 2141\\n \\n \\n "
>> }
>> ]
>> }
>>
>>   - name: "Create list of configured VLANs per Device."
>> set_fact:   
>>   device_list: "{{ device_call_filtered.matches | 
>> map(attribute='vlan-id') | list }}"
>> delegate_facts: true
>> 
>> # Debug of device_list. Output shortened for readability.
>> ok: [some_switch] => {
>> "msg": [
>> [
>> "2141", 
>> "2056"
>> ]
>> ]
>> }
>>
>>   - name: "Get difference."
>> set_fact:
>>   difference_list: "{{ cmdb_list | difference(device_list) }}"
>>   
>> ^ So that's not going to work in this state.
>>
>>

-- 
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/3eb306e4-a3b8-404d-9835-e2b7b278e190%40googlegroups.com.


[ansible-project] Re: Confused newbie - ERROR! the field 'hosts' is required but was not set

2019-08-15 Thread Zolvaring
The problem in this case is just the yaml syntax. "-" denotes the start of 
a new item, typically in a list, so when you write:

- hosts
- name

You are actually writing two separate objects, when what you want is:

- name: "download artifactory"
  hosts: all


On Thursday, August 15, 2019 at 6:23:05 PM UTC-7, GM wrote:
>
> Hi there - first I will post my response from when I run my playbook:
>
> ansible-playbook -vv glen.yml
>
> ansible-playbook 2.5.2
>   config file = /etc/ansible/ansible.cfg
>   configured module search path = 
> [u'/home/gmillard/.ansible/plugins/modules', 
> u'/usr/share/ansible/plugins/modules']
>   ansible python module location = /usr/lib/python2.7/site-packages/ansible
>   executable location = /usr/bin/ansible-playbook
>   python version = 2.7.15 (default, May  9 2018, 11:32:33) [GCC 7.3.1 
> 20180130 (Red Hat 7.3.1-2)]
> Using /etc/ansible/ansible.cfg as config file
>
> PLAYBOOK: glen.yml 
> ***
> 2 plays in glen.yml
>
> PLAY [all] 
> ***
>
> TASK [Gathering Facts] 
> ***
> task path: /home/gmillard/myplatform/OtherStuff/glen.yml:2
> ok: [fedoracontrol]
> META: ran handlers
> META: ran handlers
> META: ran handlers
> ERROR! the field 'hosts' is required but was not set
>
> Now, I'll post the playbook itself:
> ---
> - hosts: all
> - name: "download artifactory"
>   tasks:
>   - get_url:
>   url: 
> http://10.10.10.170:8081/artifactory/generic-local-repo/FilesArchive.tar.gz
>   headers:  
> "X-JFrog-Art-Api:x"
>   dest: $PWD
>   mode: 0644
>
> Two things:
> 1. Why am I getting the *ERROR! the field 'hosts' is required but was not 
> set - * I'm thinking that my formatting/indentations are incorrect.
> 2. I'm attempting to grab an artifact from JFrog Artifactory - using the 
> get_url module - am I using it correctly?  
>
> Any and all help is appreciated. Thanks in advance.
>
> G
>
>
>

-- 
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/a520f148-78a3-49c6-a125-67571a904bfe%40googlegroups.com.


[ansible-project] Re: Confused newbie - ERROR! the field 'hosts' is required but was not set

2019-08-15 Thread Zolvaring
In regards to your second question (sorry I missed it), the module looks 
okay except you need to indent the module out one more indentation space:
- name:
  hosts:
  tasks:
- get_url:
url:

The only other thing that looks immediately wrong to me is your destination 
parameter -- I don't think "$PWD" will work in this case ansible won't 
resolve the command as you execute it. If you are trying to put it in the 
current working directory of the ansible executor you can try "./" or 
specify the directory with set_fact or a variable.
  

On Thursday, August 15, 2019 at 6:23:05 PM UTC-7, GM wrote:
>
> Hi there - first I will post my response from when I run my playbook:
>
> ansible-playbook -vv glen.yml
>
> ansible-playbook 2.5.2
>   config file = /etc/ansible/ansible.cfg
>   configured module search path = 
> [u'/home/gmillard/.ansible/plugins/modules', 
> u'/usr/share/ansible/plugins/modules']
>   ansible python module location = /usr/lib/python2.7/site-packages/ansible
>   executable location = /usr/bin/ansible-playbook
>   python version = 2.7.15 (default, May  9 2018, 11:32:33) [GCC 7.3.1 
> 20180130 (Red Hat 7.3.1-2)]
> Using /etc/ansible/ansible.cfg as config file
>
> PLAYBOOK: glen.yml 
> ***
> 2 plays in glen.yml
>
> PLAY [all] 
> ***
>
> TASK [Gathering Facts] 
> ***
> task path: /home/gmillard/myplatform/OtherStuff/glen.yml:2
> ok: [fedoracontrol]
> META: ran handlers
> META: ran handlers
> META: ran handlers
> ERROR! the field 'hosts' is required but was not set
>
> Now, I'll post the playbook itself:
> ---
> - hosts: all
> - name: "download artifactory"
>   tasks:
>   - get_url:
>   url: 
> http://10.10.10.170:8081/artifactory/generic-local-repo/FilesArchive.tar.gz
>   headers:  
> "X-JFrog-Art-Api:x"
>   dest: $PWD
>   mode: 0644
>
> Two things:
> 1. Why am I getting the *ERROR! the field 'hosts' is required but was not 
> set - * I'm thinking that my formatting/indentations are incorrect.
> 2. I'm attempting to grab an artifact from JFrog Artifactory - using the 
> get_url module - am I using it correctly?  
>
> Any and all help is appreciated. Thanks in advance.
>
> G
>
>
>

-- 
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/0d54478a-72b5-4b6c-8e8e-1d526f8c1c0b%40googlegroups.com.


[ansible-project] New Ansible releases 2.8.4, 2.7.13, and 2.6.19

2019-08-15 Thread Toshio Kuratomi
Hi all- we're happy to announce that the general releases of Ansible
2.8.4, 2.7.13, and 2.6.19 are now available!


How do you get it?
--

$ pip install ansible==2.8.4 --user
or
$ pip install ansible==2.7.13 --user
or
$ pip install ansible==2.6.19 --user

The tar.gz of the releases can be found here:

* 2.8.4
  https://releases.ansible.com/ansible/ansible-2.8.4.tar.gz
  SHA256: a0153e2de3619b7e307df179cd91a3c3804cf1fe048273fe4ea5238b76679ff1
* 2.7.13
  https://releases.ansible.com/ansible/ansible-2.7.13.tar.gz
  SHA256: 339c87a1bf9e8555ce1e1c1a9452d8ed1df240944ec1a3fc2e813e6c7d70aeae
* 2.6.19
  https://releases.ansible.com/ansible/ansible-2.6.19.tar.gz
  SHA256: dbcfc9ddf620d05e1147b4c713738045a67c32be7260b11cbdbd84e92b77ca06


What's new in 2.8.4, 2.7.13, and 2.6.19
---

2.7.13 and 2.6.19 are security releases containing a fix for
CVE-2019-10206.  2.8.4 is a maintenance release containing numerous
bugfixes in addition to a fix for CVE-2019-10206 and CVE-2019-10217
(the latter does not affect 2.7.13 and 2.6.19).

CVEs fixed:
* CVE-2019-10206:  Avoid templating passwords from the command prompt
as templating may reveal secret information.
* CVE-2019-10217: Add no_log to credential fields in gcp_* modules so
that these modules do not display credentials on stdout or save them
to log iles.

The full changelogs for these releases are at:

* 2.8.4
  
https://github.com/ansible/ansible/blob/stable-2.8/changelogs/CHANGELOG-v2.8.rst
* 2.7.13
  
https://github.com/ansible/ansible/blob/stable-2.7/changelogs/CHANGELOG-v2.7.rst
* 2.6.19
  
https://github.com/ansible/ansible/blob/stable-2.6/changelogs/CHANGELOG-v2.6.rst


What's the schedule for future maintenance releases?


Future maintenance releases of 2.8.4 will occur approximately every 3
weeks.  So expect
the next one around 2019-09-05.

2.7.x and 2.6.x are released on an as needed basis for critical and
security bugfixes respectively.

Porting Help


We've published a porting guide at
https://docs.ansible.com/ansible/devel/porting_guides/porting_guide_2.8.html to
help migrate your content to 2.8.


If you discover any errors or if any of your working playbooks break when you
upgrade to 2.8.4, please use the following link to report the regression:

  https://github.com/ansible/ansible/issues/new/choose

In your issue, be sure to mention the Ansible version that works and the one
that doesn't.

Thanks!

-Toshio Kuratomi

-- 
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/CAPrnkaTKB%3DTsY8JZ3K7LR4tqU4NgHXVz28HGbNs7yx%2BbQhb6bQ%40mail.gmail.com.


Re: [ansible-project] What is the best way to manage machines that aren't defined as hosts?

2019-08-15 Thread Zolvaring
I'm not sure I understand fully, but none of the hosts you are configuring
need Ansible to be installed for you make changes remotely. Instead of
defining your hosts in a CSV, define your hosts as part of Ansible
inventory and your tasks will loop through them naturally. You can also
group hosts as you had mentioned, and run task or assign vars to specific
groups, just as you had in your example. To execute a play only on remote
esxi servers one way is:

- name: configure esxi hosts
  hosts: esxi-hosts
  roles:
 - your roles here

If I run this play and have 5 esxi hosts in my inventory group, then this
will run all roles or tasks each time for each of those 5 servers in
parallel

Making use of group_vars files and host_vars files can change the play vars
based on the group.


On Thu, Aug 15, 2019, 9:15 PM Kurt Robinson  wrote:

> I intend to Ansible to run deployment configuration on a number of Dell
> ESXi hosts in VMware using VMware and OpenManage modules.
>
> In my past ansible training, my playbooks have always run from hosts that
> I have defined in an inventory file. The machines I wish to configure don't
> have ansible installed so they will be managed from the localhost node.
>
> My question is, what is the best practice in running configuration tasks
> on these machines that aren't actual hosts within ansible?
>
> Currently, I am thinking of creating a csv file which will contain the
> host information, then loop through each host and run my tasks to run on
> each host using read_csv.
>
>
>
> pseudo:
>
> - name: Read csv and send to task
>   csv_read: csvname.csv
>   task:
> - taskname
>   passvar:
> - csv.hostname
>
> 
>
> - name : Run task
>   loop: name in csv.hostnames
> do: something
>
>
>
> To me this seems like I am under-engineering the solution a bit. Is there
> a better way I can do this?
>
> Would I be able to add the list of hosts that I want to configure to an
> inventory file, then reference a group for which I will run my
> configurations on?
>
> E.g.
>
> inventory
>
> [management]
> 10.0.0.1
> 10.0.0.2
>
> [database]
> 10.1.0.1
> 10.1.0.2
>
> __
>
> - name: Set DNS on hosts
>   vmware_module:
> hostname: '{{ management group }}'
> dns: 1.2.3.4
>
>
>
> Thanks for taking the time.
>
>
> --
> 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/2c702252-eae3-461e-842f-989e80d88537%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/CAKEXu85Ga7EadHRB%3DyP8hCQqy7S%2BTqCKmkCp%2BTj5CV10LpL5Ew%40mail.gmail.com.


[ansible-project] What is the best way to manage machines that aren't defined as hosts?

2019-08-15 Thread Zolvaring
I'm not sure I understand fully, but none of the hosts you are configuring need 
Ansible to be installed for you make changes remotely. Instead of defining your 
hosts in a CSV, define your hosts as part of Ansible inventory and your tasks 
will loop through them naturally. You can also group hosts as you had 
mentioned, and run task or assign vars to specific groups, just as you had in 
your example. To execute a play only on remote esxi servers one way is:

- name: configure esxi hosts
  hosts: esxi-hosts
  roles:
 - your roles here

If I run this play and have 5 esxi hosts in my inventory group, then this will 
run all roles or tasks each time for each of those 5 servers in parallel

Making use of group_vars files and host_vars files can change the play vars 
based on the group.

-- 
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/e1640dc5-3875-46f2-95f2-fe3f9efc4819%40googlegroups.com.


[ansible-project] What is the best way to manage machines that aren't defined as hosts?

2019-08-15 Thread Zolvaring
Seeing that you may want to loop through actual guests, I would still define 
them as Ansible inventory hosts if you know them ahead of time, and if you need 
to run tasks from a different host by invoking VMware module then try:

- name: do a thing to a guest
  vmware_module:
regular_module_args
  delegate_to: localhost (or somewhere else)

The end result will still naturally loop your inventory but will run from 
whichever host you delegate the commands to.

-- 
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/5823722d-4152-48ad-8b0b-b288e9604b8a%40googlegroups.com.