[ansible-project] variables defined in the Inventory

2017-08-11 Thread wenxing zheng
Dear all,

I have an inventory defined in the way below:

[Group1]
> host1
>
 

> [Group1:vars]
> package_name: aaa 

foo: bar
>
 

> [Group2]
> host1
>
 

> [Group2:vars]
> package_name: bbb
> foo1: bar



then I defined a playbook for the hosts with: Group2. But when I execute 
the playbook, I found the package_name was in aaa instead of bbb.

What's the problem here?

Thanks for the advice
Regards, Wenxing

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1d0b86c2-1cb3-4835-9ae7-64717c1fa6dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] variables defined in the Inventory

2017-08-11 Thread Kai Stian Olstad

On 11. aug. 2017 09:20, wenxing zheng wrote:

Dear all,

I have an inventory defined in the way below:

[Group1]
host1

[Group1:vars]
package_name: aaa
foo: bar

[Group2]
host1

[Group2:vars]
package_name: bbb
foo1: bar

then I defined a playbook for the hosts with: Group2. But when I execute
the playbook, I found the package_name was in aaa instead of bbb.

What's the problem here? >


There is no problem, this is how Ansible work.

You always get all the variables for a host regardless from where the 
variable is defined, inventory, group_vars and host_vars.


So in you example host1 will always have foo and foo1 defined.
And since package_name is set two times for host1 only the last one will 
stick since the variable is overwritten.



--
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3ee7a19a-eed2-8c43-c6f7-ec82221e7491%40olstad.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] variables defined in the Inventory

2017-08-11 Thread wenxing zheng
Get it. Many thanks for the feedback. 

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/13c9e029-ddbe-4ce2-a31c-047096c3b56e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Add conditionals to debug msg

2017-08-11 Thread Kai Stian Olstad

On 11. aug. 2017 08:25, Ryan wrote:


Sorry, I will attache the error next time.


But you didn't include all relevant output.



I tried indenting it to the same column as name and debug, but it still
failed.  If I change the command to something that returns a value for
sel_out, the debug msg returns the expected output.  The error only comes
when sel_out is not defined.

- name: Print results
debug:
  msg:
- "Board: {{ ansible_product_name }}"
- "CPU: {{ ansible_processor[1] }}   Cores: {{
ansible_processor_cores }}   CPU Count: {{ ansible_processor_count }}"
- "Memory: {{ ansible_memtotal_mb }}"
- "ansible processor count: {{ ansible_processor_count }}"
- "Log File: {{ logfile }}"
- "{{ out.stdout.split('\n') }}"
- "{{sel_out.stdout.split('\n') }}"
when: sel_out is defined


fatal: [192.168.100.11]: FAILED! => {"ansible_job_id":
"717909993947.50020", "changed": true, "cmd": "ipmitool sel list | grep -i
ecc", "delta": "0:00:00.088089", "end": "2017-08-11 06:02:57.289040",
"failed": true, "finished": 1, "rc": 1, "start": "2017-08-11
06:02:57.200951", "stderr": "", "stderr_lines": [], "stdout": "",
"stdout_lines": []} >


This error has noting to do with you debug task, it's the task you 
running "ipmitool sel list"
Had you included more information about this error you would have seen 
that easy a few lines before this statement.


grep isn't finding any ecc in the output av return code 1, this means 
failure to ansible.

To change this you have can add "changed_when" to the task.


--
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/78385974-9deb-9c76-5d13-3e2d8c0334ab%40olstad.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] delegate_to and ansible_host

2017-08-11 Thread Vladimir-csp

All hosts are already in the inventory. The delegation breaks when 
ansible_host variable is given on the command line.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/52d38003-2f1b-4e80-944e-57363448077e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Unable to manage snapshots for non-existing VM

2017-08-11 Thread Prabahar S
Hi Team,

Can you please resolve this I got an error while I'm executing this 
playbook. For my play try to take VMware snapshot. It's large ESXi host 
center need to take some specific server snapshot

Here my playbook configuration:


---
- hosts: test
  tasks:
- name: Create snapshot
  vmware_guest_snapshot:
datacenter: "***"
hostname: ***
username: ***
password: ***
name: "{{ ansible_hostname }}"
uuid: "{{ ansible_product_uuid }}"
state: present
snapshot_name: test1
description: patch_snapshot
validate_certs: False
  delegate_to: localhost


Error:
=

ansible-playbook snapshot.yml

PLAY [test] 


TASK [Gathering Facts] 
*
ok: []

TASK [Create snapshot] 
*
fatal: [***-> localhost]: FAILED! => {"changed": false, "failed": true, 
"msg": "Unable to manage snapshots for non-existing VM "}
to retry, use: --limit @/etc/ansible/snapshot.retry

PLAY RECAP 
*
**   : ok=1changed=0unreachable=0failed=1



-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c0ff92c0-01c0-49d2-b399-08ad626bce8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] ansible-galaxy git clone failures

2017-08-11 Thread Prasoon Majumdar
Hello,

I was trying to clone roles using ansible-galaxy cli from private repo, 

requirements file : working.yml


- src: git+https://g...@git.xx.com/devops/ansible-role-fpm.git
  name: watever.fpm
  version: master

ansible-galaxy install --role-file=ansible-galaxy.yml 
--roles-path="${PWD}/roles/" --force

But its throwing errors like:


[WARNING]: - fpm was NOT installed successfully: - command git clone 
https://g...@git.xx.com/devops/ansible-role-fpm.git
.fpm failed in directory /tmp/tmpGS0PhX (rc=128)

ERROR! - you can use --ignore-errors to skip failed roles and finish 
processing the list.

I tried different combinations of "git+ssh" but nothing worked, i can 
easily clone it directory using "git clone" way but ansible-galaxy way is 
not working, ideas ???

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f3a32105-06b7-4ffd-a04b-b29828e60217%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Marshalling Cisco AireOS/WLC devices with ansible

2017-08-11 Thread John Z
Modules were commited to github in the past week that support aireos 
commands and aireos configuration.  I've just started woking with them and 
have successfully run a couple commands on test WLCs. The support looks 
good and well integrated with the rest of ansible: persistent connections, 
ansible userid and password variables are used, lots of important 
functions.  

Cisco WLCs commands often prompt before they complete; I'm not sure how 
well the new support handles that yet.

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/0add700a-53f8-470d-ab47-cadeb6b2cfca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Variables between playbooks

2017-08-11 Thread marta . albecka1
Thanks I guess I will put it into a new file.

W dniu czwartek, 10 sierpnia 2017 19:35:04 UTC+2 użytkownik Kai Stian 
Olstad napisał:
>
> On 09. aug. 2017 22:56, marta.a...@gmail.com  wrote: 
> > I have some problem and I can't figure out the answear to it. I'm 
> > relatively new to Ansible so I'm still learning. I have to separate 
> > playbooks and I want to set a variable value in one, and use it in the 
> > other. So for example in playbook 1 I want to start ec2 instance and I 
> want 
> > to safe its instance_id and in the next playbook run some time after 
> that 
> > first I want to delete this instance so I want to get the instance_id 
> value 
> > from the variable. Is this possible, and if so how? If someone knows the 
> > answear please provide some simple example, because I have found some 
> > ideas, but nothing seems to work. And if the first problem could be 
> solved, 
> > would it be possible to save this variable in the first playbook with 
> parameterized 
> > variable name? 
>
> It's not possible to share variables between playbooks, you can share 
> between play in the same playbook. 
>
> What you could do is store the values in a file that you read in 
> playbook number two. 
>
> -- 
> 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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/7e84566b-83d6-4386-93ee-dd7e5f96678d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] run expect task in virtualenv, and not other tasks

2017-08-11 Thread John Lofgren
I'm having trouble figuring out how I can run a task with 'expect' module 
in a virtualenv and not have my other tasks run in that virtualenv.

The only way I've found to run an expect task in a virtualenv is to 
set_fact ansible_python_interpreter, but once I've done that, I cannot 
unset it, so all python-related tasks that run after that also run in the 
same virtualenv. Is there some way to set the python interpreter for only a 
single expect task?

I use pew (https://github.com/berdario/pew) for managing virtualenvs, but 
that is likely not relevant.

Thanks,
John

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f43d30e0-47d3-43bd-a318-09ae4a1da456%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] ansible shell module passing backslashes with double quotes

2017-08-11 Thread Abey Thomas
 Hi,

I am trying to execute the command
 'aws --debug waf-regional associate-web-acl --web-acl-id {{ ACLid }} 
--resource-arn {{ LBARN }}'
via module shell or command but I am getting errors. aws command uses the 
boto and boto is getting requests with backslashes \"WebACLId\" instead of 
"WebACLId" and \"ResourceArn\" instead of "ResourceArn"


Why is ansible command/shell module adding a backslash followed by double 
quotes?
\"

How can I remove the backslash?

I am using ansible version 2.4.0  from devel with boto 2.46.1

Regards,

Abey

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/9cef8178-95b2-4f62-8d74-df30b79a5fa4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] F5 Playbook to generate and upload UCS

2017-08-11 Thread Tariq Iqbal
Hello,

I would like to use Ansible to create a playbook that generates and uploads 
the UCS to a centralized repository.  What module can I use to accomplish 
this task?  Any help in this regards will be greatly appreciated.

Regards,
Tariq

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/433c8e64-85fd-4f08-9b26-08882882f59e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Re: Not able to ping windows machine through Ansible (winrm using credential option as CredSSP is being used)

2017-08-11 Thread Chris
Do you need CredSSP?  I would try NTLM if not.  Maybe run NETSTAT see if it 
shows 5986 open and listening if you haven't already.  You can also run 
winrm enumerate winrm/config/listener on the host to see if a hostname is 
assigned.  When did you install pywinrm.  If it's been a while might want 
to install newest version.  

On Friday, August 4, 2017 at 1:32:02 AM UTC-7, Soniya panwar wrote:
>
> sorry my mistake, *ansible_port:=5985* just typing mistake.
> and i changed port 5985 to 5986, that is why it is 5986
>
> On Friday, August 4, 2017 at 10:43:30 AM UTC+5:30, benno joy wrote:
>>
>> Seems like it is using https  5986 and you have specified 5985 , maybe 
>> because there is a ':' in your variable ansible_port:=5985, is this a 
>> typo ? and make sure the variables are applied to the task/play 
>>
>>
>>
>> On Fri, Aug 4, 2017 at 1:02 PM, Soniya panwar  
>> wrote: 
>> > Thanks for the reply, 
>> > i applied all these thing but not able to solve my problem. 
>> > 
>> > please look into the logs also and provide the possible solution: 
>> > 
>> > 2017-08-04 10:19:54,570 urllib3.connectionpool Starting new HTTPS 
>> connection 
>> > (1): X.X.X.X 
>> > 2017-08-04 10:19:54,598 urllib3.connectionpool https://X.X.X.X:5986 
>> "POST 
>> > /wsman HTTP/1.1" 401 0 
>> > 2017-08-04 10:19:54,599 urllib3.connectionpool Resetting dropped 
>> connection: 
>> > X.X.X.X 
>> > 2017-08-04 10:19:54,612 urllib3.connectionpool https://X.X.X.X:5986 
>> "POST 
>> > /wsman HTTP/1.1" 401 0 
>> > 2017-08-04 10:19:54,614 urllib3.connectionpool https://X.X.X.X:5986 
>> "POST 
>> > /wsman HTTP/1.1" 401 0 
>> > 2017-08-04 10:19:54,616 urllib3.connectionpool https://X.X.X.X:5986 
>> "POST 
>> > /wsman HTTP/1.1" 401 0 
>> > 2017-08-04 10:19:54,619 urllib3.connectionpool https://X.X.X.X:5986 
>> "POST 
>> > /wsman HTTP/1.1" 401 0 
>> > 2017-08-04 10:19:54,642 urllib3.connectionpool https://X.X.X.X:5986 
>> "POST 
>> > /wsman HTTP/1.1" 200 1632 
>> > 2017-08-04 10:19:54,648 urllib3.connectionpool https://X.X.X.X:5986 
>> "POST 
>> > /wsman HTTP/1.1" 200 847 
>> > 2017-08-04 10:19:54,653 urllib3.connectionpool https://X.X.X.X:5986 
>> "POST 
>> > /wsman HTTP/1.1" 500 1267 
>> > 
>> > 2017-08-04 10:19:54,655 p=8231 u=root |   [WARNING]: FATAL ERROR DURING 
>> FILE 
>> > TRANSFER: Traceback (most recent call last):   File 
>> > "/usr/lib/python2.7/site-packages/ansible/plugins/connection/winrm.py", 
>> line 
>> > 267, in _winrm_exec self._winrm_send_input(self.protocol, 
>> self.shell_id, 
>> > command_id, data, eof=is_last)   File "/usr/lib/python2.7/site- 
>> > packages/ansible/plugins/connection/winrm.py", line 248, in 
>> > _winrm_send_input protocol.send_message(xmltodict.unparse(rq))   
>> File 
>> > "/usr/lib/python2.7/site- 
>> > packages/winrm/protocol.py", line 207, in send_message return 
>> > self.transport.send_message(message)   File 
>> > "/usr/lib/python2.7/site-packages/winrm/transport.py", 
>> > line 202, in send_message raise WinRMTransportError('http', 
>> > error_message) WinRMTransportError: (u'http', u'Bad HTTP response 
>> returned 
>> > from server. Code 500') 
>> > 
>> > 2017-08-04 10:19:54,658 urllib3.connectionpool https://X.X.X.X:5986 
>> "POST 
>> > /wsman HTTP/1.1" 200 757 
>> > 2017-08-04 10:19:54,660 urllib3.connectionpool https://X.X.X.X:5986 
>> "POST 
>> > /wsman HTTP/1.1" 200 602 
>> > 2017-08-04 10:19:54,665 p=8231 u=root |  X.X.X.X | FAILED! => { 
>> > "failed": true, 
>> > "msg": "winrm send_input failed" 
>> > 
>> > 
>> > On Tuesday, August 1, 2017 at 6:04:32 PM UTC+5:30, To Versus wrote: 
>> >> 
>> >> I think you should run powershell script on your windows machine with 
>> >> -EnableCredSSP option like below. 
>> >> 
>> >> powershell.exe -File ConfigureRemotingForAnsible.ps1 -EnableCredSSP 
>> >> 
>> >> If you have already do this, it is helpful to run ansible module with 
>> >> -v option. 
>> >> 
>> >> ansible windows -m win_ping -v 
>> >> 
>> >> You can see the following statement on the command line if CredSSP 
>> >> authentification mode is properly configured. 
>> >> 
>> >> WINRM CONNECT: transport=credssp 
>> endpoint=https://:/wsman 
>> >> 
>> >> As a reference, below is my settings in group variable file: 
>> >> 
>> >> ansible_port: 5986 
>> >> ansible_connection: winrm 
>> >> ansible_winrm_server_cert_validation: ignore 
>> >> ansible_winrm_transport: credssp 
>> >> 
>> >> It is noted that I'm also using the same ansible version 2.3.1.0 on 
>> CentOS 
>> >> 7. 
>> >> 
>> > -- 
>> > 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 post to this group, send email to ansible...@googlegroups.com. 
>> > To view this discussion on the web visit 
>> > 
>> https://groups.google.com/d/msgid/ansible-project/ee0e29c2-237b-4fec-adc4-c13141d17f06%40googlegroups.com.
>>  

Re: [ansible-project] Re: ansible_ssh_pass parameter with salt encrypt value of ansible_user password makes client server Unreachable on playbook run

2017-08-11 Thread Lorenzo Farinas
I found a way to generate key pair using RSA on Ansible control machine, 
copied the public key to the client's /.ssh/authorized_keys.  When I run a 
playbook, it prompts me for the password I used to protect the private 
key.  I followed the SSH Agent Forwarding with Ansible notes by configuring 
the ssh_args parameter in the /etc/ansible/ansible.cfg file and the 
SSH_AUTH_SOCK Defaults parameter in the /etc/sudoers file of the client; 
but I'm still getting prompted with the password for private key on 
playbook run.  What's the procedure to make the playbook run passwordless?  
- Thanks, Lorenzo

On Thursday, August 10, 2017 at 11:04:16 AM UTC-10, Dick Visser wrote:
>
> On 10 August 2017 at 21:19, Lorenzo Farinas  > wrote: 
> > Please provide the procedure on how to add ssh-agent and ssh keys to the 
> > client with reference to Ansible control machine.  My research on this 
> task 
> > is not productive.  - Thanks, Lorenzo 
>
> Working with SSH keys and agents is considered a basic sysadmin skill 
> and and a prerequisite for ansible, so if this turns out to be 
> problematic then 
> it's a good idea to get familiar with this first. 
> This list isn't the right place for that, but the topic is thoroughly 
> documented on numerous places on the internet. 
>
>
> -- 
> Dick Visser 
> GÉANT 
>
> Want to join us? We're hiring: https://www.geant.org/jobs 
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/97bc875f-06bf-492e-8503-337950b06908%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Re: Permissions issue, cannot become root

2017-08-11 Thread prakash ranjan
I am also facing the same issue. tried several options but no solution.

Unable to take privilege of "sudo su -". 

This is content of my playbook. Commented ones shows that I have tried 
those options. I have also tried many options with command lines.

---
- hosts: all
#  remote_user: root
#  become: yes
#  become_method: sudo
#  become_exe: "sudo su -"
  become_user: root
  tasks:
 - name: run adhoc command which required root priviledge
#   command: /usr/bin/cat /root/ab
shell: su monitor -l -c "/usr/bin/cat /root/ab"
#   remote_user: root
#   become: yes #true
#   become_method: sudo
#   become_flags: '-u' # '-s /bin/sh'
#   become_user: root

-Prakash

On Monday, July 3, 2017 at 8:14:44 PM UTC-7, Brian Coca wrote:
>
> you don't even need become_user: root as that is the default. 
>
> -- 
> Brian Coca 
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a11dd1b1-7135-4d51-9ec6-2283d982e181%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] New to ansible -- Looping through files with wildcards

2017-08-11 Thread John Harmon
Hi all,

I am new to ansible and am looking for some help.  I don't mind finding the 
answer on my own; however, I could use a shove in the right direction.

I need to modify some files (/etc/sysconfig/network-scripts/ifcfg-* 
files).  I was trying to use with_fileglob (among other options), but I 
read somewhere that wont work ( 
https://stackoverflow.com/questions/29831690/ansible-with-fileglob-not-matching-files-with-only-wildcard
 
)

Basically, I am looking to run a loop against all ifcfg-* files.  I want to 
modify some entries (which I can do individually) and delete some entries 
(which I can also do individually), I just don't know how to approach 
looping through all of the files.  I am even unsure if fileglob is the 
right approach.  I would appreciate some education on the matter.  How 
would you approach it?

Thanks,
john


-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/9d0dc197-97a9-4770-90e1-e902a9299a49%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: New to ansible -- Looping through files with wildcards

2017-08-11 Thread John Harmon
Trying this (which doesn't delete the lines yet) but the other problem 
is that the shell task is not idempotent

---
# tasks file for dns_update
- name: Retrieve ifcfg files in /etc/sysconfig/network-scripts
  shell:  ls /etc/sysconfig/network-scripts | grep ^ifcfg-
  register: path_files

- name: Removing all DNS entries in ifcfg-* files
  lineinfile:
path: /etc/sysconfig/network-scripts/{{ path_files.stdout_lines }}
state: absent
regexp: '^DNS'
  with_items: "{{ path_files.stdout_lines }}"

RESULTS

PLAY [test] 
**

TASK [Gathering Facts] 
***
ok: [ansibletest-rhel7]
ok: [ansibletest-rhel6]
ok: [ansibletest-oel6]

TASK [dns_update : Retrieve ifcfg files in /etc/sysconfig/network-scripts] 
***
changed: [ansibletest-rhel7]
changed: [ansibletest-rhel6]
changed: [ansibletest-oel6]

TASK [dns_update : Removing all DNS entries in ifcfg-* files] 

ok: [ansibletest-rhel7] => (item=ifcfg-bond0)
ok: [ansibletest-rhel6] => (item=ifcfg-bond0)
ok: [ansibletest-oel6] => (item=ifcfg-bond0)
ok: [ansibletest-rhel7] => (item=ifcfg-eth0)
ok: [ansibletest-rhel6] => (item=ifcfg-eth0)
ok: [ansibletest-oel6] => (item=ifcfg-eth0)
ok: [ansibletest-rhel7] => (item=ifcfg-eth1)
ok: [ansibletest-rhel6] => (item=ifcfg-eth1)
ok: [ansibletest-rhel7] => (item=ifcfg-eth2)
ok: [ansibletest-oel6] => (item=ifcfg-eth1)
ok: [ansibletest-rhel6] => (item=ifcfg-eth2)
ok: [ansibletest-rhel7] => (item=ifcfg-eth3)
ok: [ansibletest-oel6] => (item=ifcfg-eth2)
ok: [ansibletest-rhel7] => (item=ifcfg-eth4)
ok: [ansibletest-rhel6] => (item=ifcfg-eth3)
ok: [ansibletest-rhel7] => (item=ifcfg-eth5)
ok: [ansibletest-oel6] => (item=ifcfg-eth3)
ok: [ansibletest-rhel6] => (item=ifcfg-eth4)
ok: [ansibletest-rhel7] => (item=ifcfg-lo)
ok: [ansibletest-rhel6] => (item=ifcfg-eth5)
ok: [ansibletest-oel6] => (item=ifcfg-eth4)
ok: [ansibletest-rhel6] => (item=ifcfg-lo)
ok: [ansibletest-oel6] => (item=ifcfg-eth5)
ok: [ansibletest-oel6] => (item=ifcfg-lo)

PLAY RECAP 
***
ansibletest-oel6   : ok=3changed=1unreachable=0failed=0
ansibletest-rhel6  : ok=3changed=1unreachable=0failed=0
ansibletest-rhel7  : ok=3changed=1unreachable=0failed=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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ca145f16-714b-48d4-a69f-3ac7f079bb18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Re: New to ansible -- Looping through files with wildcards

2017-08-11 Thread Kai Stian Olstad

On 11. aug. 2017 22:59, John Harmon wrote:

Trying this (which doesn't delete the lines yet) but the other problem
is that the shell task is not idempotent


What do you mean by "is not idempotent" it's just listing files and it 
need to do that every time.




---
# tasks file for dns_update
- name: Retrieve ifcfg files in /etc/sysconfig/network-scripts
   shell:  ls /etc/sysconfig/network-scripts | grep ^ifcfg-
   register: path_files


Alternative is the find module
- name: Retrieve ifcfg files in /etc/sysconfig/network-scripts
  find:
paths: ls /etc/sysconfig/network-scripts
pattern: ifcfg-*
  register: path_files



- name: Removing all DNS entries in ifcfg-* files
   lineinfile:
 path: /etc/sysconfig/network-scripts/{{ path_files.stdout_lines }}
 state: absent
 regexp: '^DNS'
   with_items: "{{ path_files.stdout_lines }}"


The value from with_items i in a variable called item so the path sould be
  path: /etc/sysconfig/network-scripts/{{ item }}


With the find module above this task should look like this
- name: Removing all DNS entries in ifcfg-* files
   lineinfile:
 path: '{{ item.path }}'
 state: absent
 regexp: '^DNS'
   with_items: '{{ path_files.files }}'


--
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/12bf9e46-a6f2-f905-eb0a-7557c0486c9c%40olstad.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: New to ansible -- Looping through files with wildcards

2017-08-11 Thread John Harmon
Forgive me for responding to myself... I just hope that someone in the 
future might find this relevant/useful.

added "changed_when: false" to the shell task.  That took care of the 
idempotent issue I was seeing by overriding the change result.

Still plugging away on the other issue

- name: Disabling NetworkManager in ifcfg-* files
  lineinfile:
path: /etc/sysconfig/network-scripts/{{path_files.stdout_lines}}
regexp: '^NM_CONTROLLED'
line: "NM_CONTROLLED=no"

The above is now returning:
TASK [dns_update : Disabling NetworkManager in ifcfg-* files] 

fatal: [ansibletest-rhel7]: FAILED! => {"changed": false, "failed": true, 
"msg": "Destination /etc/sysconfig/network-scripts/[u'ifcfg-bond0', 
u'ifcfg-eth0', u'ifcfg-eth1', u'ifcfg-eth2', u'ifcfg-eth3', u'ifcfg-eth4', 
u'ifcfg-eth5', u'ifcfg-lo'] does not exist !", "rc": 257}
fatal: [ansibletest-rhel6]: FAILED! => {"changed": false, "failed": true, 
"msg": "Destination /etc/sysconfig/network-scripts/[u'ifcfg-bond0', 
u'ifcfg-eth0', u'ifcfg-eth1', u'ifcfg-eth2', u'ifcfg-eth3', u'ifcfg-eth4', 
u'ifcfg-eth5', u'ifcfg-lo'] does not exist !", "rc": 257}
fatal: [ansibletest-oel6]: FAILED! => {"changed": false, "failed": true, 
"msg": "Destination /etc/sysconfig/network-scripts/[u'ifcfg-bond0', 
u'ifcfg-eth0', u'ifcfg-eth1', u'ifcfg-eth2', u'ifcfg-eth3', u'ifcfg-eth4', 
u'ifcfg-eth5', u'ifcfg-lo'] does not exist !", "rc": 257}

Notice the ifcfg* names are messed up.  I am trying to narrow down the 
reason

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e77a3ea6-5cc6-442e-812e-46fc7ad2bdb7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Add conditionals to debug msg

2017-08-11 Thread Ryan
I tried adding "changed_when" for when sel_out is not defined, but it gives 
me an error, so I am not sure how to use "changed_when" in this case. 
 What's the correct usage?

 - name: Check for ECC's
   shell: ipmitool sel list | grep -i ecc
   register: sel_out
   changed_when: sel_out is not defined
   async: 3
   poll: 2

fatal: [192.168.100.11]: FAILED! => {"ansible_job_id": 
"186470565638.100676", "changed": false, "cmd": "ipmitool sel list | grep 
-i ecc", "delta": "0:00:00.094723", "end": "2017-08-12 01:40:04.893313", 
"failed": true, "finished": 1, "rc": 1, "start": "2017-08-12 
01:40:04.798590", "stderr": "", "stderr_lines": [], "stdout": "", 
"stdout_lines": []}


I was able to use this method, which seems to work.  Is this the correct 
usage of "|| true"?

 - name: Check for ECC's
   shell: ipmitool sel list | grep -i ecc || true
   register: sel_out
   async: 3
   poll: 2


With the above usage, I am back to my original question.  How can I add 
conditionals to individual items in a debug msg list?  For instance, how 
can I add a conditional only for "{{sel_out.stdout.split('\n') }}"?  If i 
put the "when" in the same column as "name" and "debug" as Dick suggested, 
then it will impact the full debug msg list, not only the sel_out line.

 - name: Print results
   debug:
msg:
   - "Board: {{ ansible_product_name }}"
   - "CPU: {{ ansible_processor[1] }}   Cores: {{ 
ansible_processor_cores }}   CPU Count: {{ ansible_processor_count }}"
   - "Memory: {{ ansible_memtotal_mb }}"
   - "ansible processor count: {{ ansible_processor_count }}"
   - "Log File: {{ logfile }}"
   - "{{ out.stdout.split('\n') }}"
   - "{{sel_out.stdout.split('\n') }}"



On Friday, August 11, 2017 at 2:51:29 AM UTC-7, Kai Stian Olstad wrote:
>
> On 11. aug. 2017 08:25, Ryan wrote: 
> > 
> > Sorry, I will attache the error next time. 
>
> But you didn't include all relevant output. 
>
>
> > I tried indenting it to the same column as name and debug, but it still 
> > failed.  If I change the command to something that returns a value for 
> > sel_out, the debug msg returns the expected output.  The error only 
> comes 
> > when sel_out is not defined. 
> > 
> > - name: Print results 
> > debug: 
> >   msg: 
> > - "Board: {{ ansible_product_name }}" 
> > - "CPU: {{ ansible_processor[1] }}   Cores: {{ 
> > ansible_processor_cores }}   CPU Count: {{ ansible_processor_count }}" 
> > - "Memory: {{ ansible_memtotal_mb }}" 
> > - "ansible processor count: {{ ansible_processor_count }}" 
> > - "Log File: {{ logfile }}" 
> > - "{{ out.stdout.split('\n') }}" 
> > - "{{sel_out.stdout.split('\n') }}" 
> > when: sel_out is defined 
> > 
> > 
> > fatal: [192.168.100.11]: FAILED! => {"ansible_job_id": 
> > "717909993947.50020", "changed": true, "cmd": "ipmitool sel list | grep 
> -i 
> > ecc", "delta": "0:00:00.088089", "end": "2017-08-11 06:02:57.289040", 
> > "failed": true, "finished": 1, "rc": 1, "start": "2017-08-11 
> > 06:02:57.200951", "stderr": "", "stderr_lines": [], "stdout": "", 
> > "stdout_lines": []} > 
>
> This error has noting to do with you debug task, it's the task you 
> running "ipmitool sel list" 
> Had you included more information about this error you would have seen 
> that easy a few lines before this statement. 
>
> grep isn't finding any ecc in the output av return code 1, this means 
> failure to ansible. 
> To change this you have can add "changed_when" to the task. 
>
>
> -- 
> 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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fca35767-8f48-45a9-a251-624dd07ea7df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.