Re: [ansible-project] Why can I debug this variable syntax but not set_fact the same variable syntax?

2017-07-12 Thread burns498
Kai - Thank you very much. Everything you mentioned was exactly right. 
Helped me learn a thing or two about proper syntax...and reminding me not 
to code too late into the evening. haha.

Final Playbook:
---
- name: Target Host
  hosts: "{{ target }}"
  tasks:
  - name: Register foo
command: 'echo Hello World'
register: foo

- name: Different Host
  hosts: ptl01a0fap005
  tasks:
#  - debug: var=hostvars[groups['{{ target }}'][0]]['foo']['stdout']
  - debug: var=hostvars[groups[target][0]]['foo']['stdout']

  - name: set_fact bar
set_fact:
  bar: "{{ hostvars[groups[target][0]]['foo']['stdout'] }}"

  - debug: var=bar

Final Output:
wmspt@dtl01lnxap01a:/staging_manh/manhattanansible$ ansible-playbook 
pb-output-test.yml -e  "target=Test5" -i 'inventories/staging/inventory' 

PLAY [Target Host] 
*

TASK [setup] 
***
ok: [ptl01a0fap006]

TASK [Register foo] 

changed: [ptl01a0fap006]

PLAY [Different Host] 
**

TASK [setup] 
***
ok: [ptl01a0fap005]

TASK [debug] 
***
ok: [ptl01a0fap005] => {
"hostvars[groups[target][0]]['foo']['stdout']": "Hello World"
}

TASK [set_fact bar] 

ok: [ptl01a0fap005]

TASK [debug] 
***
ok: [ptl01a0fap005] => {
"bar": "Hello World"
}

PLAY RECAP 
*
ptl01a0fap005  : ok=4changed=0unreachable=0failed=0 
  
ptl01a0fap006  : ok=2changed=1unreachable=0failed=0 
  

wmspt@dtl01lnxap01a:/staging_manh/manhattanansible$ 

Thank you!

On Wednesday, July 12, 2017 at 9:02:21 AM UTC-5, Kai Stian Olstad wrote:
>
> On 12. juli 2017 06:36, burn...@umn.edu  wrote: 
> > Why does this syntax work for debug but not set_fact? How can I actually 
> > use the debug output on the other host? 
>
> Pure luck that the debug work and you yaml syntax is wrong of set_fact. 
>
>
> > *Playbook:* 
> > --- 
> > - name: Target Host 
> >hosts: "{{ target }}" 
> >tasks: 
> >- name: Register foo 
> >  command: 'echo Hello World' 
> >  register: foo 
> > 
> > - name: Different Host 
> >hosts: ptl01a0fap005 
> >tasks: 
> >- debug: var=hostvars[groups['{{ target }}'][0]]['foo']['stdout'] 
>
> You should not use {{ }} and ', correct syntax is 
>
>- debug: var=hostvars[groups[target][0]]['foo']['stdout'] 
>
> > 
> >- name: set_fact bar 
> >  set_fact: 
> >bar=hostvars['{{ target }}'][0]]['foo']['stdout'] 
>
>  
>
> >- name: set_fact bar 
> >  set_fact: 
> >bar="{{ hostvars['{{ target }}'][0]]['foo']['stdout'] }}" 
> This is wrong yaml syntax. 
>
> bar= should be bar: 
>
> And also here you can't use {{ }} inside a template, and a '' indicate a 
> string not a variable. 
>
> Correct syntax is 
>
>bar: "{{ hostvars[target][0]]['foo']['stdout'] }}" 
>
>
> But I guess this will also fail since target=Test5 that is a group, so 
> it will not find hostvars for a host called Test5. Maybe you forgot to 
> include the group as you did in debug 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/d8d27d10-96e0-42dd-9cbd-7023f7b53ef1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Why can I debug this variable syntax but not set_fact the same variable syntax?

2017-07-11 Thread burns498
Hello - I'm trying to register a variable on dynamic host {{ target }} and 
use it on a different host ptl01a0fap005. The dynamic host {{ target }} is 
passed in as an extra-var on the command line.

I've found that I can successfully debug the variable I want on the 
different host, in green below. However, if I try to set_fact the with the 
same syntax it fails. The last attempt would normally work, but in this 
case doesn't due to the nested variable.

Why does this syntax work for debug but not set_fact? How can I actually 
use the debug output on the other host?

*Playbook:*
---
- name: Target Host
  hosts: "{{ target }}"
  tasks:
  - name: Register foo
command: 'echo Hello World'
register: foo

- name: Different Host
  hosts: ptl01a0fap005
  tasks:
  - debug: var=hostvars[groups['{{ target }}'][0]]['foo']['stdout']

  - name: set_fact bar
set_fact:
  bar=hostvars['{{ target }}'][0]]['foo']['stdout']

  - debug: var=bar

  - name: set_fact bar
set_fact:
  bar="{{ hostvars['{{ target }}'][0]]['foo']['stdout'] }}"

  - debug: var=bar

*Output:*
wmspt@dtl01lnxap01a:/staging_manh/manhattanansible$ ansible-playbook 
pb-output-test.yml -e "target=Test5" -i 'inventories/staging/inventory' 

PLAY [Target Host] 
*

TASK [setup] 
***
ok: [ptl01a0fap006]

TASK [Register foo] 

changed: [ptl01a0fap006]

PLAY [Different Host] 
**

TASK [setup] 
***
ok: [ptl01a0fap005]

TASK [debug] 
***
ok: [ptl01a0fap005] => {
"hostvars[groups['Test5'][0]]['foo']['stdout']": "Hello World"
}

TASK [set_fact bar] 

ok: [ptl01a0fap005]

TASK [debug] 
***
ok: [ptl01a0fap005] => {
"bar": "hostvars['Test5'][0]]['foo']['stdout']"
}

TASK [set_fact bar] 

fatal: [ptl01a0fap005]: FAILED! => {"failed": true, "msg": "template error 
while templating string: unexpected ']'. String: {{ hostvars['{{ target 
}}'][0]]['foo']['stdout'] }}"}
to retry, use: --limit 
@/staging_manh/manhattanansible/pb-output-test.retry

PLAY RECAP 
*
ptl01a0fap005  : ok=4changed=0unreachable=0failed=1 
  
ptl01a0fap006  : ok=2changed=1unreachable=0failed=0 
  

wmspt@dtl01lnxap01a:/staging_manh/manhattanansible$ 


Thank you

-- 
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/2a643cd8-d9bb-430b-8c64-58c6846ae84a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Ansible log_path to also include the command line that invoked ansible-playbook?

2017-07-10 Thread burns498
Question - Is it also possible for Ansible log_path 
to log 
the actual command that was used to invoke the ansible-playbook?

It does a great job of tracking tasks and status, but I can't see the 
command itself. Would be helpful to know if a tag was skipped, command line 
var was passed, or other command line change that isn't immediately clear 
by the output.

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To 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/d7f7fa3a-058c-4043-89b9-bc16903a506f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Include_vars with predefined variables?

2017-05-01 Thread burns498
Hello - Can include_vars also include predefined variables? I have a 
variable {{ WMS_HOME }} which debug resoles properly but include_vars 
doesn't carry it through.

*role/vars/SDN500.yml*

> backup_files:
> - src_path: "{{ WMS_HOME }}/distribution/"
>   filename: "scope.war"
>   dest_path: "{{ SDN_backup_dir }}/{{ code_tier }}/{{ 
> inventory_hostname_short }}/scope/"
>

*Code:*
- name: Include vars for SDN list
  tags: sdnlist
  include_vars: "{{ item }}.yml"
  register: include_vars_output
  with_items: "{{ SDNs }}"

- debug: msg="Home={{ WMOS_HOME }}"
  tags: sdnlist

- debug: msg="Src Path={{ item.src_path }}"
  tags: sdnlist
  with_items: "{{ backup_files }}"

*Output:*

> TASK [role_utility_sdn_backups : Include vars for SDN list] 
> 
> ok: [host] => (item=SDN500)
> TASK [role_utility_sdn_backups : debug] 
> 
> ok: [host] => {
> "msg": "Home=/apps/scope/manh/WM"
> }
> TASK [role_utility_sdn_backups : debug] 
> 
> ok: [host] => (item={u'filename': u'scope.war', u'src_path': u'{# WMS_HOME 
> #}/distribution/', u'dest_path': u'{# SDN_backup_dir #}/{# code_tier #}/{# 
> inventory_hostname_short #}/scope/'}) => {
> "item": {
> "dest_path": "{# SDN_backup_dir #}/{# code_tier #}/{# 
> inventory_hostname_short #}/scope/", 
> "filename": "scope.war", 
> "src_path": "{# WMS_HOME #}/distribution/"
> }, 
> "msg": "Src Path=/distribution/"
> }


Thanks 

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To 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/d7549dbb-3a19-4210-9ac8-54de582fa679%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Struggling with complex lists and dictionaries

2017-04-28 Thread burns498
Hello Ansible Project - Assistance requested.

I'm attempting to create a new playbook that heavily uses loop iterations 
over lists and dictionaries.This is my first time using loops of any 
significance within Ansible, and I fear I've bit off more than I can chew.

*The Goal: *Create a playbook to deploy a list of application fixpacks, but 
first backup all of the required files of said fixpacks. 

Currently I have something like the below approach:

   1. User passes JSON *list *on command line as extra-var {{ FPs }}
   2. Items in JSON list are used to include_vars
   3. role vars contain a *list *of *dictionaries*
   4. Loop over the list of include_vars, which has a list of dictionaries 
   to backup required files.

Sample code thus far...

*1) Command Line*

> ansible-playbook pb.yml --extra-vars '{ "FPs": ['FP1','FP2'] }'
>

*2) Include Vars*
- name: Include vars for FP list
  include_vars: "{{ item }}.yml"
  register: include_vars_output
  with_items: "{{ FPs }}"

*3) role vars*:
# FP1.yml

# List of Dictionaries
backup_files:
- src_path: "{{ HOME }}/distribution/"
  filename: "scope.war"
  dest_path: "{{ Backup_dir }}/scope/"
- src_path: "{{ HOME }}/cbs/bin/"
  filename: "PkPreProcessDOC"
  dest_path: "{{ Backup_dir }}/cbs/bin/"

# FP2.yml

# List of Dictionaries
backup_files:
- src_path: "{{ HOME }}/distribution/"
  filename: "build.xml"
  dest_path: "{{ Backup_dir }}/scope/"

*4) Backup required files before deployment*
Disclaimer: Code breaks here since I can't figure out how to parse out the 
variables I need
- name: Backup files
  copy:
src: "{{ item.src_path }}{{ item.filename }}"
dest: "{{ item.dest_path }}{{ item.filename }}.pre{{ item.item }}"
remote_src: yes
  with_items: "{{ include_vars_output.results.ansible_facts.backup_files }}"

*Sample include_vars_output.results debug output:*

> {
> "item": {
> "ansible_facts": {
> "backup_files": [
> {
> "dest_path": "{# Backup_dir #}/scope/", 
> "filename": "scope.war", 
> "src_path": "{# HOME #}/distribution/"
> }
> ]
> }, 
> "invocation": {
> "module_args": {
> "_raw_params": "FP1.yml"
> }, 
> "module_name": "include_vars"
> }, 
> "item": "FP1"
> }
> }


*Error Text:*

> [DEPRECATION WARNING]: Skipping task due to undefined Error, in the future 
> this will be a 
> fatal error.: 'list object' has no attribute 'ansible_facts'.
> This feature will be removed 
> in a future release. Deprecation warnings can be disabled by setting 
> deprecation_warnings=False in ansible.cfg.


Example above is two fixpacks with a total of 3 files to backup. I end up 
with a rather deep list of lists. of lists.. of dictionaries. 

I've checked syntax , loops 
, and examples 
but
 
can't seem to dig myself out. 
It may well be that I am approaching this all wrong or attempting the 
impossible.

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To 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/408a6a84-68db-46d1-87ce-41c7340ad4b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Handling ansible.cfg file for distributed version controlled projects

2017-04-19 Thread burns498
All - A question about ansible.cfg maintenance for distributed version 
controlled projects. This may be more of a general version control question 
than anything specific to Ansible, but figured you all may have ran into 
this before.

In my ansible.cfg file, I have a hard coded log_path to where I want logs 
to write. When I clone the repo, I would need to update this variable to 
the new log location. If I don't, then logs from staging may write into 
production and cause merge conflicts. How are you all maintain ansible.cfg 
files that get cloned around via version control tools? 

I have a Git origin master (production) and a clone (staging) on the same 
server. There are some other custom variables in my ansible.cfg. They 
remain static, but I can't just use the default ansible.cfg under /etc/. I 
can't use the default log location because this server is used by more than 
one project, so I need to write my logs to my own spot.

So far I've tried combinations of .gitignore, git assume-unchanged, and git 
cached. All of them work up front, but aren't sustainable for new clones or 
long term use.

Any thoughts? Thank you!

-- 
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/228dd11d-5f9c-4c19-907e-bdd03cf4bf0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Command module and quotes

2017-03-17 Thread burns498
Hello everyone - I have a simply quotation question that I can't seem to 
find an answer to online for some reason.

What is the proper way to wrap this command module task, such that the 
embedded quotes and variables still pass through properly?

- name: Gather {{ uid }} system account password
# Requires the CLI agent to be installed and configured on the target 
server.
# Uses the delegate_to command to ensure CLI is run on proper node. Defined 
in group_vars.
  tags: CLI
  command: '/opt/CARKaim/sdk/clipasswordsdk GetPassword -p 
AppDescs.AppID={{ CA_AppID }} -p Query="Safe={{ DIRECTORY_CA_Safe 
}};Folder=Root;Object={{ WMSADMIN_CA_Object }}" -p 
RequiredProps=Address,UserName -o Password'
  register: wmsadmin_dir_account_pass
  changed_when: false
  delegate_to: "{{ CyberArkCLI_hostname_short }}"


I have the whole command wrapped in single quotes and I want to retain the 
raw double quotes inside the command. If I review the -vvv output, I see 
this. It looks like Ansible/YAML is parsing the command and dropping the 
quotes I have in the code. 
 

>  "cmd": ["/opt/CARKaim/sdk/clipasswordsdk", "GetPassword", "-p", 
> "AppDescs.AppID=", "-p", 
> "Query=Safe=;Folder=Root;Object=", "-p", 
> "RequiredProps=Address,UserName", "-o", "Password"] 


How shall I change this up to retain those quotes?

-- 
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/76b694c0-cfd5-43fa-8826-e20359a1f0db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Questions for "Ansible Alternative Directory Structure" with split inventories

2017-01-03 Thread burns498
Thank you both for the responses! This was very helpful.

I ended up creating a 'production' and 'staging' sub directories just like 
the Ansible sample. I removed the overall ansible.cfg inventory location, 
and instead used the 'ANSIBLE_INVENTORY' environment variable in the 
,profile for each account. In my deployment, we already have separate 
accounts for PL vs DR so it worked out quite well. In this fashion, PL and 
DR can properly load their own host_vars without requiring and additional 
command line arguments. There is just some additional first time setup 
config to accommodate this.

Thank you!

On Tuesday, January 3, 2017 at 10:42:50 AM UTC-6, Kevin Bullock wrote:
>
> > On Jan 3, 2017, at 10:30, burn...@umn.edu  wrote: 
> > 
> > Hello - Thanks for the response. 
> > 
> > Yea right now I have a top level ansible.cfg that already points to my 
> own inventory file (currently just one). 
> > 
> > I guess I'm still not connecting the dots as to how site.yml (in their 
> example) would know which inventory, host_vars, and group_vars to load. Is 
> there an ansible.cfg that also needs to be split into the 'production' and 
> 'staging' directories? 
> > 
> > If I used the environment variable option that you presented above, I'm 
> assuming I would load that in the .profile for the user running the 
> playbook? In that way my PL user and DR user would each point to their own 
> inventory file (via the .profile when the shell is opened) even before the 
> ansible playbook is executed. Also, I wouldn't have to hard code the 
> inventory into the playbook or the command line. Am I thinking about that 
> right? Sorry for the perhaps simple question, I'm still getting used to 
> Linux systems. 
>
> You don't need to create separate users. Environment variables can be set 
> for a single shell session, or you can use Ansible's `-i` flag to specify 
> the inventory per-run instead. 
>
> I have a fair bit of experience using multiple inventories in the same 
> repo now. Here's the setup I'd recommend: 
>
> * Specify the default inventory you want to use in ansible.cfg (hostfile = 
> path/to/prod/). 
> * Override the default when you're configuring the DR environment 
> (ansible-playbook playbook.yml -i path/to/pldr/). 
>
> Another strategy I've used for per-inventory options: set the correct 
> variables in a file in your Ansible repo, and source that in your shell 
> when you want to work on that environment, e.g.: 
>
> # /path/to/ansible/repo/prodvars.sh 
> # For example let's say you need to set options for ec2.py: 
> AWS_REGION=us-west-2 
> AWS_PROFILE=profilename 
> # ...and the inventory or other Ansible params: 
> ANSIBLE_INVENTORY=path/to/prod/ 
>
> (Note: in case the convention isn't clear, wherever it says `path/to/...` 
> above, replace that with the real path.) 
>
> pacem in terris / мир / शान्ति / ‎‫سَلاَم‬ / 平和 
> Kevin R. Bullock 
>
>

-- 
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/4e9c15ce-9c1b-44b7-b7a4-1b9bf259becf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Questions for "Ansible Alternative Directory Structure" with split inventories

2017-01-03 Thread burns498
Hello - Thanks for the response.

Yea right now I have a top level ansible.cfg that already points to my own 
inventory file (currently just one). 

I guess I'm still not connecting the dots as to how site.yml (in their 
example) would know which inventory, host_vars, and group_vars to load. Is 
there an ansible.cfg that also needs to be split into the 'production' and 
'staging' directories?

If I used the environment variable option that you presented above, I'm 
assuming I would load that in the .profile for the user running the 
playbook? In that way my PL user and DR user would each point to their own 
inventory file (via the .profile when the shell is opened) even before the 
ansible playbook is executed. Also, I wouldn't have to hard code the 
inventory into the playbook or the command line. Am I thinking about that 
right? Sorry for the perhaps simple question, I'm still getting used to 
Linux systems. 

Would the host_vars and group_vars then come along via the same solve as 
the inventory file? Or are those separate environment variables? I thought 
the host_vars and group_vars, by default, look in the same top location as 
where the playbook is executed,,?

Thanks for the help!



On Tuesday, January 3, 2017 at 9:05:49 AM UTC-6, J Hawkesworth wrote:
>
> Default inventory file is usually /etc/ansible/hosts, although you can 
> override this by setting something different in your ansible.cfg (along 
> with a lot of other options - see 
> http://docs.ansible.com/ansible/intro_configuration.html )
>
> As well as using -i to specify which inventory you want to load you can 
> also set an environment variable.
>
>export ANSIBLE_INVENTORY=your_inventory_file
>
>
> Hope this helps,
>
> Jon
>
> On Tuesday, January 3, 2017 at 2:41:45 PM UTC, burn...@umn.edu wrote:
>>
>> Hello - 
>>
>> I have a use case where I have two of the same apps installed on one 
>> server in a shared Prod-Like/Disaster Recovery (PL/DR) environment. I use 
>> Ansible to automate application configuration tasks for each app on the 
>> server. As of right now, this isn't working for PL/DR because Ansible has 
>> no way to determine which host_vars are required. Does it load PL or does 
>> it load DR? 
>>
>> I did some searching and found Ansible Best Practices - Alternative 
>> Directory Layout 
>> .
>>  
>> It looks like this might solve my problem. It splits out a "production" and 
>> "staging" directory. Each has their own host, group, and inventory files. 
>>
>> My questions are are around how this works? What is the "glue" such that 
>> Ansible knows how to find certain files? In their example layout, how does 
>> the playbook "site.yml" know to load the 'production' inventory versus the 
>> 'staging' inventory? Is it all hard coded user facts? Does it assume we 
>> specify '-i' each time?
>>
>> Any info, other examples, or other potential solves for this would be 
>> much appreciated. 
>>
>> Thank you!
>>
>

-- 
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/52b2bd47-f2fd-4687-9112-5c1c1cc2c9e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Ansible stdout_lines writes as list syntax [u'text1',u'text2'] instead of multiline?

2016-12-29 Thread burns498
Hello Jon - Thanks for the help!

The change you suggested did help clean it up a bit. It changed it from a 
list output to one line string separated by literal '\n'. Something like 
"2a3\n> echo hi". This was a step in the right direction.

I did some more digging around and found an answer using Jinja2 whitespace 
control . 
Uses a for loop to parse the list output via jinja2 filters.
*Updated Code Snippet:*
- name: Log diff changes
  blockinfile:
dest: "{{ log_dir }}/{{ pb_diff_logname }}"
content: |
  {{ app_log_header }}
  Command: 'diff {{ deployed_copy_output.dest }} {{ 
deployed_copy_output.backup_file }}'
  {% for item in diff_output.stdout_lines %}
  {{ item }}
  {% endfor %}
  {{ app_log_footer }}
create: yes
insertafter: EOF
marker: "{{ app_log_marker }}"

The output is then quite clean in the log file.

> **
> Command: 'diff /opt/wmspt/.profile 
> /opt/wmspt/.profile.2016-12-29@08:57:50~'
> 2a3
> > echo hi
> **


Thanks!

On Thursday, December 29, 2016 at 1:14:04 AM UTC-6, J Hawkesworth wrote:
>
> Try using join, like this
>
> {{ results.stdout_lines | join ('\n') }}
>
> Not tried, but hope it helps,
>
> Jon 
>
>

-- 
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/5fd8619c-d23c-4bd5-ba1d-10a9ed69fe53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Ansible stdout_lines writes as list syntax [u'text1',u'text2'] instead of multiline?

2016-12-28 Thread burns498
Hello - Assistance requested with stdout_lines output.

I have some tasks that take diff results of two files and then writes the 
output to a log.

Code Snippet:
- name: Gather diff output of deployed changes
  command: "diff {{ deployed_copy_output.dest }} {{ 
deployed_copy_output.backup_file }}"
  register: diff_output
  failed_when: diff_output.rc > 1

- name: Log diff changes
  blockinfile:
dest: "{{ log_dir }}/{{ pb_diff_logname }}"
content: |
  {{ app_log_header }}
  Command: 'diff {{ deployed_copy_output.dest }} {{ 
deployed_copy_output.backup_file }}'
  {{ diff_output.stdout_lines }}
  {{ app_log_footer }}
create: yes
insertafter: EOF
marker: "{{ app_log_marker }}"

This results in output that looks like the below. 

> **
> Command: 'diff /opt/wmspt/.profile 
> /opt/wmspt/.profile.2016-12-28@23:06:41~'
> [u'2a3', u'> echo hi']
> **


I would expect it to look more like the debug output:

> TASK [role_config_shared_profile : debug] 
> **
> ok: [ptl01a0fap006] => {
> "diff_output": {
> "changed": false, 
> "cmd": [
> "diff", 
> "/opt/wmspt/.profile", 
> "/opt/wmspt/.profile.2016-12-28@23:27:24~"
> ], 
> "delta": "0:00:00.111675", 
> "end": "2016-12-28 23:27:25.068251", 
> "failed": false, 
> "failed_when_result": false, 
> "rc": 1, 
> "start": "2016-12-28 23:27:24.956576", 
> "stderr": "", 
> "stdout": "2a3\n> echo hi", 
> "stdout_lines": [
> "2a3", 
> "> echo hi"
> ], 
> "warnings": []
> }
> }  


Writing the stdout_lines has some sort of list syntax with 
[u'text1',u'text2'], even though debug the same info is correct multiline 
output. Is there something that I'm missing here?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 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/5a25ad27-5eff-48de-bf06-216ae9894d51%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Ansible does not properly extract a tarball using unarchive module?

2016-12-28 Thread burns498
Hello - I'm seeking some assistance in unpackaging a tarball using Ansible.

I'm using the unarchive module to unpackage a tarball to a remote server. 
The tarball is stored localled on the Ansible server, and I want it 
extracted on the target server. 

*Code Snippet:*
- name: Prepare variables for WM dal_SDN180.tar changes
  set_fact:
filename="dal_SDN180.tar"
ma_app="WM"


- name: Deploy file to target
# Unzip using Ansible unarchive module
  tags: deploy
  unarchive:
src: "{{ filename }}"
dest: "{{ WMS_HOME }}/swtools/"
  register: deployed_copy_output
 
*-vvv output:*

> ok: [ptl01a0fap006] => {"changed": false, "dest": 
> "/apps/scope/manh/WM/swtools/", "gid": 2345, "group": "g_wmspt", "handler": 
> "TarArchive", "invocation": {"module_args": {"backup": null, "content": 
> null, "copy": true, "creates": null, "delimiter": null, "dest": 
> "/apps/scope/manh/WM/swtools/", "directory_mode": null, "exclude": [], 
> "extra_opts": [], "follow": false, "force": null, "group": null, 
> "keep_newer": false, "list_files": false, "mode": null, 
> "original_basename": "dal_SDN180.tar", "owner": null, "regexp": null, 
> "remote_src": null, "selevel": null, "serole": null, "setype": null, 
> "seuser": null, "src": 
> "/tmp/wmspt/ansible-tmp/ansible-tmp-1482960921.89-105630081213776/source"}}, 
> "mode": "0755", "owner": "wmspt", "secontext": 
> "unconfined_u:object_r:unlabeled_t:s0", "size": 4096, "src": 
> "/tmp/wmspt/ansible-tmp/ansible-tmp-1482960921.89-105630081213776/source", 
> "state": "directory", "uid": 3267}



When run, the play considers the task "ok" even though I know the tar file 
has different contents than the target. The tar file contains the same 
files, but the contents of those file is different. I would expect Ansible 
to nptice this and then extract the tarball. I'm able to see this behavior 
with zip files, but not tar files. I did notice that if I manually delete 
one of the files on the target server, Ansible then extracts the entire 
tarball. Manually reverting a file and rerunning Ansible still does not 
extract the tarball.

Any thoughts on what I am missing here? I reviewed this thread 
 and tried 
setting pipelining to False, but it still had the same behavior.

Thanks 

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To 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/7b97b7ce-aef5-453e-89ab-37d6556112a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Cannot generate diff with shell module

2016-11-30 Thread burns498
Hello - 

I solved a similar problem before by following a suggestion on the shell 
module  page.

To sanitize any variables passed to the shell module, you should use “{{ 
> var | quote }}” instead of just “{{ var }}” to make sure they don’t include 
> evil things like semicolons.


Based on the _raw_params in the verbose output, your variables do contain 
hyphens, colons, etc. Ansible might be interpreting these as something you 
don't want.

Maybe. Give it a shot. :)

On Wednesday, November 30, 2016 at 5:08:35 PM UTC-6, colin byrne wrote:
>
> I am trying to use the shell module to generate a diff between two remote 
> files, but it is erring out without giving me a warning or error: 
>
> - name: create diff of old settings file and new settings file
>   shell: diff /home/deploy/{{ application_name 
> }}/shared/config/settings.yml /home/deploy/{{ application_name 
> }}/shared/config/settings.yml.ansible_old_version >> /home/deploy/{{ 
> application_name }}/shared/config/settings.yml_diffs_1
>   when: settings_file.changed
>
>
> It executes totally fine when run directly in a shell on the remote 
> machine... 
>
> Here is the verbose error output, which doesn't seem to give much of use:
>
> Thanks for any help or workaround! I've spent too much time on this...
>
> fatal: [staging]: FAILED! => {"changed": true, "cmd": "diff 
> /home/deploy/app_name/shared/config/settings.yml 
> /home/deploy/app_name/shared/config/settings.yml.ansible_old_version 
> > 
> /home/deploy/coverhound/shared/config/settings.yml_diffs/settings.yml_2016-11-30_14:45:54",
>  
> "delta": "0:00:00.002778", "end": "2016-11-30 14:45:57.198400", "failed": 
> true, "invocation": {"module_args": {"_raw_params": "diff 
> /home/deploy/coverhound/shared/config/settings.yml 
> /home/deploy/app_name/shared/config/settings.yml.ansible_old_version > 
> /home/deploy/app_name/shared/config/settings.yml_diffs/settings.yml_2016-11-30_14:45:54",
>  
> "_uses_shell": true, "chdir": null, "creates": null, "executable": 
> "/bin/bash", "removes": null, "warn": true}, "module_name": "command"}, 
> "rc": 1, "start": "2016-11-30 14:45:57.195622", "stderr": "", "stdout": "", 
> "stdout_lines": [], "warnings": []}
>

-- 
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/da9e1f6c-a45c-49a1-83af-8e88898ec140%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Modify registered variable content from the copy module?

2016-11-30 Thread burns498
Hello - 

Is there a way to modify the content of a registered variable? I have a 
shared role that logs output of my deployments.

*tasks/main.yml*
- name: Log {{ filename }} changes
  blockinfile:
dest: "{{ log_dir }}/{{ pb_logname }}"
content: |
  **
  File '{{ filename }}' updated!
  Modifying role: "{{ role_path }}"
  Source file: {{ registered_content.src }}
  New file: {{ registered_content.dest }}
  Backup file: {{ registered_content.backup_file }}
  **
create: yes
insertafter: EOF
marker: ""
  when: log_type == "file change"


Thus far this has been working great because there was always a 
pre-existing file to replace. However, I just hit some config that creates 
a whole new file that never previously existed. Therefore, the first time 
it runs I get the below error.

TASK [role_config_loadbalancer : Log misc.properties changes] 
> **
> fatal: [target]: FAILED! => {"failed": true, "msg": "the field 'args' has 
> an invalid value, which appears to include a variable that is undefined. The 
> error was: 'dict object' has no attribute 'backup_file'\n\nThe error 
> appears to have been in '/manh/roles/role_utility_logging/tasks/main.yml': 
> line 2, column 3, but may\nbe elsewhere in the file depending on the exact 
> syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: Log {{ 
> filename }} changes\n  ^ here\nWe could be wrong, but this one looks like 
> it might be an issue with\nmissing quotes.  Always quote template 
> expression brackets when they\nstart a value. For instance:\n\n   
>  with_items:\n  - {{ foo }}\n\nShould be written as:\n\n   
>  with_items:\n  - \"{{ foo }}\"\n"}


In hindsight, this makes sense, since there was nothing to backup in the 
first place. So I'm wondering if I can manually add a value in 
'backup_file' field after it's already been registered? 

TASK [role_config_loadbalancer : debug] 
> 
> ok: [target] => {
> "deployed_copy_output": {
>
"backup_file": "ADD TEXT HERE",  

"changed": true, 
> "checksum": "0d4216d1a25218c5656d8e0db2e68499eba74238", 
> "dest": 
> "/apps/scope/manh/MDA/distribution/DeploymentDirector/installer/properties/misc.properties",
>  
> "gid": 2345, 
> "group": "g_wmspt", 
> "md5sum": "49552048354e51b2a5d2959a93441766", 
> "mode": "0644", 
> "owner": "wmspt", 
> "secontext": "system_u:object_r:default_t:s0", 
> "size": 9980, 
> "src": 
> "/manh/software/distribution/ansible/staged_config/ptl01a0fap006/MDA/misc.properties",
>  
> "state": "file", 
> "uid": 3267
> }
> }


This way I can continue to use the single logging role without needing to 
accommodate for corner cases like this and pollute the play output. Or 
perhaps there is a better way to design this all together. Thoughts?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To 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/f77d8db1-9ac4-431e-9b51-13b4be052440%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Parse registered output into a variable?

2016-11-29 Thread burns498
Ah - works like a charm. Thank you for the speedy response!

On Tuesday, November 29, 2016 at 2:35:05 PM UTC-6, Matt Martz wrote:
>
> set_fact:
> just_bar: "{{ output.stdout.split()|last }}"
>
> Or any other number of things.  The key there is to use set_fact to set a 
> new variable.
>
> On Tue, Nov 29, 2016 at 2:30 PM,  wrote:
>
>> Hello - Is there a way to parse registered output into a variable? 
>>
>> Pseudo Code:
>>   tasks:
>>   - name: Sample Task
>> command: 'blah'
>> register: output
>>   - debug: var=output.stdout
>>
>> TASK [debug] 
>>> ***
>>> ok: [target] => {
>>> "output.stdout": "Foo: Bar"
>>> }
>>
>>
>> So I can easily register and use "Foo: Bar". But is there a way where I 
>> can just store "Bar" for later use? 
>> For context, the command uses some black box vendor provided classes so 
>> I'm unable to change the actual output. I need to work with what is 
>> presented.
>>
>> Thank you!
>>
>> -- 
>> 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/85114542-064a-4a8b-b733-9720e108bb25%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Matt Martz
> @sivel
> sivel.net
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 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/c6de49ef-2fd9-4ad3-969f-c64aa8e55ebc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Parse registered output into a variable?

2016-11-29 Thread burns498
Hello - Is there a way to parse registered output into a variable? 

Pseudo Code:
  tasks:
  - name: Sample Task
command: 'blah'
register: output
  - debug: var=output.stdout

TASK [debug] 
> ***
> ok: [target] => {
> "output.stdout": "Foo: Bar"
> }


So I can easily register and use "Foo: Bar". But is there a way where I can 
just store "Bar" for later use? 
For context, the command uses some black box vendor provided classes so I'm 
unable to change the actual output. I need to work with what is presented.

Thank you!

-- 
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/85114542-064a-4a8b-b733-9720e108bb25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: A "first time" unexpected templating error - what did I do?

2016-11-28 Thread burns498
Thank you for the response!

For separate reasons, I ended up changing this to a local_action and then 
the issue never resurfaced. Still unsure why...and I've been monitoring it 
for awhile now. If the error reproduces I'll post the output and other info.

Thanks for the help!

On Monday, November 21, 2016 at 6:28:22 AM UTC-6, Greg Langford wrote:
>
> What happens when you run the command manually the first time round? What 
> is the exit code and what is the output, as it says a templating type error 
> occurred I would check these things first. It may be the command when first 
> run does not output what you expect it to.
>
> Kind Regards
>
> On Sunday, 20 November 2016 19:06:46 UTC, burn...@umn.edu wrote:
>>
>> Hello - Assistance requested.
>>
>> I believe I've coded a nasty bug into my ansible playbook and I'm not 
>> sure how to unravel it. In my observations, the code throws an "Unexpected 
>> templating type error occurred" whenever I *first *run a task. All 
>> subsequent runs do not throw the error again, even if I backout the changes 
>> to redo them. Some code snippets below. 
>>
>> role1/tasks/main.yml:
>> - name: database param_def select
>>   tags: db
>>   include: roles/role_utility_sqlplus/tasks/main.yml
>>   vars:
>> query_type: "select"
>> table: "param_def"
>> filename: "dbselect_paramdef_mhe.sql"
>> db_logname: "{{ WMS_Schema }}_{{ WMS_Servicename 
>> }}_db_paramdef_mhe_{{ lookup('pipe', 'date +%Y-%m-%d_%H%M%S') }}.log"
>> db_absolute_logpath: "/dev/null"
>>
>> - name: set_fact database select output
>>   tags: db
>>   set_fact:
>> db_select_output: "{{ expect_output }}"
>>
>> - name: database param_def insert
>>   tags: db
>>   include: roles/role_utility_sqlplus/tasks/main.yml
>>   vars:
>> query_type: "insert"
>> table: "param_def"
>> filename: "dbinsert_paramdef_mhe.sql"
>> db_logname: "{{ WMS_Schema }}_{{ WMS_Servicename 
>> }}_db_paramdef_mhe_{{ lookup('pipe', 'date +%Y-%m-%d_%H%M%S') }}.log"
>> db_absolute_logpath: "{{ log_dir }}/{{ db_logname }}"
>>   when: db_select_output.stdout | search("no rows selected")
>>
>> roles/role_utility_sqlplus/tasks/main.yml:
>> - name: Database - Stage {{ table }} {{ query_type }} sql from template
>>   tags: db
>>   template:
>> src={{ filename }}.j2
>> dest="{{ staged_config_dir }}/{{ inventory_hostname_short }}/{{ 
>> filename }}"
>> backup=yes
>>   changed_when: false
>>
>>
>> - name: Database - Execute {{ table }} {{ query_type }}
>>   tags: db
>>   expect:
>> command: "/bin/bash"
>> responses:
>>   \$ $:
>> - . ~/.profile
>> - "sqlplus {{ WMS_Schema }}/$PASSWORD@{{ WMS_Servicename }}"
>> - exit
>>   SQL> $:
>> - set echo on
>> - spool {{ db_absolute_logpath }}
>> - "@{{ staged_config_dir }}/{{ inventory_hostname_short }}/{{ 
>> filename }}"
>> - spool off
>> - quit
>> timeout: 5
>> echo: yes
>>   register: expect_output
>>   changed_when: query_type != "select"
>>   failed_when: expect_output.stdout | search("(ORA|SP2)-[0-9]+")
>>
>> Occasional 'first time' error:
>>
>>> TASK [role_config_mhe : Database - Execute param_def include] 
>>> ***
>>> fatal: [ptl01a0fap006]: FAILED! => {"failed": true, "msg": "The 
>>> conditional check 'expect_output.stdout | search(\"(ORA|SP2)-[0-9]+\")' 
>>> failed. The error was: Unexpected templating type error occurred on ({% 
>>> if expect_output.stdout | search(\"(ORA|SP2)-[0-9]+\") %} True {% else 
>>> %} False {% endif %}): expected string or buffer"}
>>
>>
>> Essentially, I have a role that includes a utility role for sqlplus work. 
>> It somestimes trips on the 'failed_when' statement in the included sqlplus 
>> role. I believe this has something to do with use an include (with 
>> conditional) and then that include also has conditionals, such that they 
>> are mashing together and sometimes breaking the 'template' behind the 
>> scenes. It could also be the scope of registered variable 'expect_output', 
>> which I believe I resolved by declaring 'db_select_output' in role1.
>>
>> Any thoughts? It is working right now because I let the 'first time' 
>> failures pass. Now I can't reproduce. I'm worried I have a nasty bug that 
>> will bite me later. Any advice is helpful.
>>
>> Thanks!
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To 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/8c364de4-1e51-484a-a79f-cc889e3ddcc7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Store playbook name as a 'global' variable across plays?

2016-11-28 Thread burns498
Hello - Apologies for the late reply. I failed to see the update before.

Thanks for the suggestion. I ended up defining this as a fact early on in 
my playbook.

As for your question on roles, I do agree with you. I already redesigned 
the role setup to make more sense. Thanks!

On Wednesday, November 9, 2016 at 6:25:43 PM UTC-6, Dick Davies wrote:
>
> you could set it as a group_var in your inventory. 
>
> Do you mind me asking what's going on with your roles there (I don't 
> understand what the target var is for)? 
> If you have 2 different roles that you want to apply to groups, 
> couldn't you just have multiple plays? 
>
> ... 
> ... 
> - hosts: Lower_Envs 
>   roles: 
> - role_mhe_config_lower 
>
> - hosts: Upper_Envs 
>   roles: 
> - role_mhe_config_upper 
> ... 
> ... 
>
>
>
> On 8 November 2016 at 22:59,   wrote: 
> > Hello - 
> > 
> > Is there a way to store playbook name as a 'global' variable across 
> plays?? 
> > I've seen potential options via callbacks or group_vars:all but still 
> > struggling with the solve. 
> > 
> > At the end of the day I want to log certain actions for a specific 
> playbook 
> > (which contains several different plays). I have the default ansible 
> logging 
> > setup, but it lacks readability and is otherwise difficult to consume. 
> The 
> > playbook contains all sorts of prep, validations, and deployments but I 
> only 
> > want to log the aggregate changes in our operational environments such 
> that 
> > it can be easily digested. I envision a log file with 
> > _.log with all the stuff I want to plop into 
> it. 
> > 
> > I could approach the callback; however I'm still new to ansible so 
> > hesitating before hopping into more 'advanced' features. 
> > I don't believe group_vars:all will work because the playbook name isn't 
> > tied to the host groups. 
> > Passing in the name as an extra-var on the command line reduces 
> usability. 
> > So far the best that I could do is manually define the var in the 
> playbook 
> > when calling the role. However, it then only exists for that specific 
> play. 
> > 
> > 
> > 
> > - name: MHE Dematic Conveyer Configuration 
> >   hosts: "{{ target }}" 
> >   vars: 
> > playbook_name: "pb_MA_WMOS_Post_Install_Config" 
> >   roles: 
> >   - { role: role_mhe_config_lower, when: "'Lower_Envs' in group_names", 
> > tags: ["Lower_Envs"] } 
> >   - { role: role_mhe_config_upper, when: "'Upper_Envs' in group_names", 
> > tags: ["Upper_Envs"] } 
> > 
> > 
> > Or, perhaps I'm just looking at this all wrong and restricting too much 
> down 
> > one path. Thoughts? 
> > 
> > Thanks! 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "Ansible Project" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to ansible-proje...@googlegroups.com . 
> > To 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/01de0105-bc9d-4efc-a4da-4f62ebc87ee5%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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/00c28b10-53e3-48f4-916b-1504091d71b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Ansible shell module failure?

2016-11-23 Thread burns498
So I took the shell command piece by piece, and it looks like it was 
failing due to two pipes strung together. Once I slimmted it down to ps -ef 
| grep '/apps/scope/manh/MIP/profile-root' it worked fine. My following 
conditional then handles the extra grep PID that it returns now.

On Wednesday, November 23, 2016 at 1:04:44 PM UTC-6, burn...@umn.edu wrote:
>
> Hello - Assistance requested
>
> I'm encountering a shell module failure in a play I'm testing. My end goal 
> is to validate if my app "MIP" is down or not. Plan is to check for the 
> running process, then conditionally fail out as needed. My sample shell 
> command is failing but I can't determine why. The actual error output isn't 
> helpful. 
>
> Code:
> - name: Validate MIP is down
>   hosts: "{{ target }}"
>   tasks:
>   - shell: "ps -ef | grep '/apps/scope/manh/MIP/profile-root' | grep -v 
> grep"
> #  - shell: "ps -ef | grep '{{ MIP_HOME }}/profile-root' | grep -v grep"
> register: mip_output
> changed_when: false
>
> Error Output:
>
>> wmspt@dtl01lnxap01a:/manh$ ansible-playbook pb-running-validation.yml 
>> --extra-vars "target=Test5 ant_handlers=false" -vvv
>>
>  
>
>> Using /manh/ansible.cfg as config file
>> PLAYBOOK: pb-running-validation.yml 
>> 
>> 1 plays in pb-running-validation.yml
>> PLAY [Validate MIP is down] 
>> 
>> TASK [setup] 
>> ***
>> <...>
>> ok: [ptl01a0fap006]
>> TASK [command] 
>> *
>> task path: /manh/pb-running-validation.yml:7
>> <...>
>> fatal: [ptl01a0fap006]: FAILED! => {"changed": false, "cmd": "ps -ef | 
>> grep '/apps/scope/manh/MIP/profile-root' | grep -v grep", "delta": 
>> "0:00:00.125571", "end": "2016-11-23 12:58:48.369056", "failed": true, 
>> "invocation": {"module_args": {"_raw_params": "ps -ef | grep 
>> '/apps/scope/manh/MIP/profile-root' | grep -v grep", "_uses_shell": true, 
>> "chdir": null, "creates": null, "executable": null, "removes": null, 
>> "warn": true}, "module_name": "command"}, "rc": 1, "start": "2016-11-23 
>> 12:58:48.243485", "stderr": "", "stdout": "", "stdout_lines": [], 
>> "warnings": []}
>
>
> The command itself works fine when executed manually on the target server.
>
> Perhaps it's something with the shell module 
> ? It looks like shell 
> module is frowned upon based on the docs. Perhaps there is a way to turn 
> this command into something that the actually command module can parse.
>
> Thanks
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To 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/37cb6030-4b40-4104-b13f-6d15b751ea45%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Ansible shell module failure?

2016-11-23 Thread burns498
Hello - Assistance requested

I'm encountering a shell module failure in a play I'm testing. My end goal 
is to validate if my app "MIP" is down or not. Plan is to check for the 
running process, then conditionally fail out as needed. My sample shell 
command is failing but I can't determine why. The actual error output isn't 
helpful. 

Code:
- name: Validate MIP is down
  hosts: "{{ target }}"
  tasks:
  - shell: "ps -ef | grep '/apps/scope/manh/MIP/profile-root' | grep -v 
grep"
#  - shell: "ps -ef | grep '{{ MIP_HOME }}/profile-root' | grep -v grep"
register: mip_output
changed_when: false

Error Output:

> wmspt@dtl01lnxap01a:/manh$ ansible-playbook pb-running-validation.yml 
> --extra-vars "target=Test5 ant_handlers=false" -vvv
>
 

> Using /manh/ansible.cfg as config file
> PLAYBOOK: pb-running-validation.yml 
> 
> 1 plays in pb-running-validation.yml
> PLAY [Validate MIP is down] 
> 
> TASK [setup] 
> ***
> <...>
> ok: [ptl01a0fap006]
> TASK [command] 
> *
> task path: /manh/pb-running-validation.yml:7
> <...>
> fatal: [ptl01a0fap006]: FAILED! => {"changed": false, "cmd": "ps -ef | 
> grep '/apps/scope/manh/MIP/profile-root' | grep -v grep", "delta": 
> "0:00:00.125571", "end": "2016-11-23 12:58:48.369056", "failed": true, 
> "invocation": {"module_args": {"_raw_params": "ps -ef | grep 
> '/apps/scope/manh/MIP/profile-root' | grep -v grep", "_uses_shell": true, 
> "chdir": null, "creates": null, "executable": null, "removes": null, 
> "warn": true}, "module_name": "command"}, "rc": 1, "start": "2016-11-23 
> 12:58:48.243485", "stderr": "", "stdout": "", "stdout_lines": [], 
> "warnings": []}


The command itself works fine when executed manually on the target server.

Perhaps it's something with the shell module 
? It looks like shell 
module is frowned upon based on the docs. Perhaps there is a way to turn 
this command into something that the actually command module can parse.

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To 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/17ab3ede-bf5d-40d7-8ff4-3a0d82be7956%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Scaling the Ansible Hierarchy?

2016-11-22 Thread burns498
Ok so I ended up rolling back to playbooks in the top level directory. 

I got myself turned around a bit here. The {{roles_path}} as part of the 
include actually wasn't working; which, I should have known since you can't 
use ansible.cfg parameters in tasks like that. I think my main problem is 
that I'm using 'include' statements to include roles during plays. In this 
way, I function them out as reusable functions for different roles. I was 
warned that this is a nonstandard, in favor of meta dependencies. I think 
that's coming back to bite me now.

Sample:
- name: database param_def select
# Initial select statement to see if db changes are required
  tags: db
  include: roles/role_utility_sqlplus/tasks/main.yml
  vars:
query_type: "select"
table: "param_def"
filename: "dbselect_paramdef_mhe.sql"




On Tuesday, November 22, 2016 at 12:53:02 PM UTC-6, burn...@umn.edu wrote:
>
> Thanks for the info! I tried this in my own environment, since I actually 
> had a similar question before.
>
> Moved playbooks to a playbooks dir. Set role_path=./roles. This broke my 
> include statements, which I now modified to '- include: "{{ roles_path }}
> /role_handlers_ant/handlers/main.yml"'. This is likely a better practice 
> anyway.
>
> However, it seems that my plays can no longer find my group_vars and other 
> such objects. Basic structure is below:
> ansible.cfg
> .ansible/inventory
> playbooks/
>pb.yml
> roles/
> #   roles...
> host_vars/
> #   host_vars...
> group_vars/
> #   group_vars...
>
> Should host and group vars also be moved? They worked fine before I moved 
> playbooks from top level dir to their own dir.
>
> Specifically, the error I get now is below. This is a variable defined in 
> a group_vars.
>
>> fatal: [ptl01a0fap006]: FAILED! => {"failed": true, "msg": "The 
>> conditional check ''{{ ansible_user_id }}' != '{{ wmadmin }}'' failed. The 
>> error was: error while evaluating conditional ('{{ ansible_user_id }}' != 
>> '{{ wmadmin }}'): 'wmadmin' is undefined\n\nThe error appears to have 
>> been in '/manh/roles/role_utility_preplay_validation/tasks/main.yml': line 
>> 2, column 3, but may\nbe elsewhere in the file depending on the exact 
>> syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: Ensure 
>> uid is appropriate for {{ inventory_hostname_short }}\n  ^ here\nWe could 
>> be wrong, but this one looks like it might be an issue with\nmissing 
>> quotes.  Always quote template expression brackets when they\nstart a 
>> value. For instance:\n\nwith_items:\n  - {{ foo }}\n\nShould be 
>> written as:\n\nwith_items:\n  - \"{{ foo }}\"\n"}
>
>
> Thanks 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To 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/96b57a2c-c04e-48a8-8b1d-65d4efd78f0d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Scaling the Ansible Hierarchy?

2016-11-22 Thread burns498
Thanks for the info! I tried this in my own environment, since I actually 
had a similar question before.

Moved playbooks to a playbooks dir. Set role_path=./roles. This broke my 
include statements, which I now modified to '- include: "{{ roles_path }}
/role_handlers_ant/handlers/main.yml"'. This is likely a better practice 
anyway.

However, it seems that my plays can no longer find my group_vars and other 
such objects. Basic structure is below:
ansible.cfg
.ansible/inventory
playbooks/
   pb.yml
roles/
#   roles...
host_vars/
#   host_vars...
group_vars/
#   group_vars...

Should host and group vars also be moved? They worked fine before I moved 
playbooks from top level dir to their own dir.

Specifically, the error I get now is below. This is a variable defined in a 
group_vars.

> fatal: [ptl01a0fap006]: FAILED! => {"failed": true, "msg": "The 
> conditional check ''{{ ansible_user_id }}' != '{{ wmadmin }}'' failed. The 
> error was: error while evaluating conditional ('{{ ansible_user_id }}' != 
> '{{ wmadmin }}'): 'wmadmin' is undefined\n\nThe error appears to have 
> been in '/manh/roles/role_utility_preplay_validation/tasks/main.yml': line 
> 2, column 3, but may\nbe elsewhere in the file depending on the exact 
> syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: Ensure 
> uid is appropriate for {{ inventory_hostname_short }}\n  ^ here\nWe could 
> be wrong, but this one looks like it might be an issue with\nmissing 
> quotes.  Always quote template expression brackets when they\nstart a 
> value. For instance:\n\nwith_items:\n  - {{ foo }}\n\nShould be 
> written as:\n\nwith_items:\n  - \"{{ foo }}\"\n"}


Thanks 

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To 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/b2661e80-6e45-4924-ae9e-15d6cdb447f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Can conditional "OR" operator be syntactically indented similar to the "AND" operator?

2016-11-22 Thread burns498
Thanks Brian! That YAML multiline notation worked out wonderfully for this. 
Thanks for educating me!

On Tuesday, November 22, 2016 at 9:13:24 AM UTC-6, Brian Coca wrote:
>
> Not that way but you can use YAML multiline
>
> failed_when: >
>expect_output.stdout | search("(ORA|SP2)-[0-9]+") or
>expect_output.stdout | search("Usage")
>
>
> ​The lis​t notation is just that, a list of conditionals which all must be 
> true , which ends up being an implicit AND.
>
>
> --
> 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/ba0a4f8c-3b73-4f89-91fc-c9132ecbfa3d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Can conditional "OR" operator be syntactically indented similar to the "AND" operator?

2016-11-22 Thread burns498
Hey Brian - That list notation worked out wonderfully. Thanks for educating 
me!

On Tuesday, November 22, 2016 at 9:13:24 AM UTC-6, Brian Coca wrote:
>
> Not that way but you can use YAML multiline
>
> failed_when: >
>expect_output.stdout | search("(ORA|SP2)-[0-9]+") or
>expect_output.stdout | search("Usage")
>
>
> ​The lis​t notation is just that, a list of conditionals which all must be 
> true , which ends up being an implicit AND.
>
>
> --
> 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/9044d307-fd86-46a2-9221-b483880273e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Can conditional "OR" operator be syntactically indented similar to the "AND" operator?

2016-11-21 Thread burns498
Hello -

Can the conditional "OR" operator be syntactically indented similar to the 
"AND" operator?

"AND" can be written in either of these ways: 
Source 


> when: django_migration_result|changed and ('Applying auth.0001_initial... OK' 
> in django_migration_result.stdout)
>
> or

> when:
> - django_migration_result | changed 
>  - 'Applying auth.0001_initial... OK' in django_migration_result.stdout 


"OR" can be written as:

>   failed_when: expect_output.stdout | search("(ORA|SP2)-[0-9]+") or 
> expect_output.stdout | search("Usage")

but I can't get the below attempt to work.

>   failed_when: 
> - expect_output.stdout | search("(ORA|SP2)-[0-9]+") or
> - expect_output.stdout | search("Usage")



Thoughts? 

-- 
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/bfc2021e-a4c7-4593-8dff-9075739d9601%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] A "first time" unexpected templating error - what did I do?

2016-11-20 Thread burns498
Hello - Assistance requested.

I believe I've coded a nasty bug into my ansible playbook and I'm not sure 
how to unravel it. In my observations, the code throws an "Unexpected 
templating type error occurred" whenever I *first *run a task. All 
subsequent runs do not throw the error again, even if I backout the changes 
to redo them. Some code snippets below. 

role1/tasks/main.yml:
- name: database param_def select
  tags: db
  include: roles/role_utility_sqlplus/tasks/main.yml
  vars:
query_type: "select"
table: "param_def"
filename: "dbselect_paramdef_mhe.sql"
db_logname: "{{ WMS_Schema }}_{{ WMS_Servicename }}_db_paramdef_mhe_{{ 
lookup('pipe', 'date +%Y-%m-%d_%H%M%S') }}.log"
db_absolute_logpath: "/dev/null"

- name: set_fact database select output
  tags: db
  set_fact:
db_select_output: "{{ expect_output }}"

- name: database param_def insert
  tags: db
  include: roles/role_utility_sqlplus/tasks/main.yml
  vars:
query_type: "insert"
table: "param_def"
filename: "dbinsert_paramdef_mhe.sql"
db_logname: "{{ WMS_Schema }}_{{ WMS_Servicename }}_db_paramdef_mhe_{{ 
lookup('pipe', 'date +%Y-%m-%d_%H%M%S') }}.log"
db_absolute_logpath: "{{ log_dir }}/{{ db_logname }}"
  when: db_select_output.stdout | search("no rows selected")

roles/role_utility_sqlplus/tasks/main.yml:
- name: Database - Stage {{ table }} {{ query_type }} sql from template
  tags: db
  template:
src={{ filename }}.j2
dest="{{ staged_config_dir }}/{{ inventory_hostname_short }}/{{ 
filename }}"
backup=yes
  changed_when: false


- name: Database - Execute {{ table }} {{ query_type }}
  tags: db
  expect:
command: "/bin/bash"
responses:
  \$ $:
- . ~/.profile
- "sqlplus {{ WMS_Schema }}/$PASSWORD@{{ WMS_Servicename }}"
- exit
  SQL> $:
- set echo on
- spool {{ db_absolute_logpath }}
- "@{{ staged_config_dir }}/{{ inventory_hostname_short }}/{{ 
filename }}"
- spool off
- quit
timeout: 5
echo: yes
  register: expect_output
  changed_when: query_type != "select"
  failed_when: expect_output.stdout | search("(ORA|SP2)-[0-9]+")

Occasional 'first time' error:

> TASK [role_config_mhe : Database - Execute param_def include] 
> ***
> fatal: [ptl01a0fap006]: FAILED! => {"failed": true, "msg": "The 
> conditional check 'expect_output.stdout | search(\"(ORA|SP2)-[0-9]+\")' 
> failed. The error was: Unexpected templating type error occurred on ({% 
> if expect_output.stdout | search(\"(ORA|SP2)-[0-9]+\") %} True {% else %} 
> False {% endif %}): expected string or buffer"}


Essentially, I have a role that includes a utility role for sqlplus work. 
It somestimes trips on the 'failed_when' statement in the included sqlplus 
role. I believe this has something to do with use an include (with 
conditional) and then that include also has conditionals, such that they 
are mashing together and sometimes breaking the 'template' behind the 
scenes. It could also be the scope of registered variable 'expect_output', 
which I believe I resolved by declaring 'db_select_output' in role1.

Any thoughts? It is working right now because I let the 'first time' 
failures pass. Now I can't reproduce. I'm worried I have a nasty bug that 
will bite me later. Any advice is helpful.

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To 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/1eb9b3ec-b792-44e3-94a1-d983fb99542a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Save remote property value to registered variable?

2016-11-15 Thread burns498
Hello - 

Is there a way to save a remote property value to a registered variable?

Example: Remote server has file stuff.properties with below sample content:

> var1=Hello
> var2=World


Can Ansible reach out to that file, crack it open, find key "var2", then 
register value "World"? I dont' want the entire stuff.properties file, but 
just the value "World" from key "var2".

In my head, I imagine there may be some way to setup a regex backrefrence 
to slurp out "World". Or, perhaps first fetch 
, then lookup 
, with a fancy INI 
plugin 
 
logic?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To 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/834728c2-5eb0-47c1-9324-355fa4969f5a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Inconsistent regex search results in where conditional?

2016-11-09 Thread burns498
Ah excellent! Thanks for the assistance!

On Thursday, November 3, 2016 at 4:45:02 PM UTC-5, Kai Stian Olstad wrote:
>
> On 03. nov. 2016 21:27, burn...@umn.edu  wrote: 
> > Hello - I am working through some seemingly inconsistent results for 
> regex 
> > search results in where clauses. 
> > 
> > I'm trying to take actions when stdout contains a certain regex pattern. 
> I 
> > have one method using shell module, and now testing using a preferred 
> > expect module that I'm trying to get to work. The shell method properly 
> > logs based on the when-search conditional. The expect skips the same 
> > conditional, despite writing output for the same script. Below I have 
> > pasted the play, code, and both outputs for reference. 
>
> The expect output is not the same as you get from shell,  line ending in 
> expect output is \r\n. 
>
> The best way to check the output is using debug module right after the 
> expect task like so 
>
> - debug: var=expect_output 
>
> and then adjust your regex accordingly. 
>
> -- 
> 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/2a3eafce-5aca-4e6c-b42e-d02fadf4e49c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Store playbook name as a 'global' variable across plays?

2016-11-08 Thread burns498
Hello -

Is there a way to store playbook name as a 'global' variable across plays?? 
I've seen potential options via callbacks 
 or group_vars:all 
 but 
still struggling with the solve.

At the end of the day I want to log certain actions for a specific playbook 
(which contains several different plays). I have the default ansible 
logging setup, but it lacks readability and is otherwise difficult to 
consume. The playbook contains all sorts of prep, validations, and 
deployments but I only want to log the aggregate changes in our operational 
environments such that it can be easily digested. I envision a log file 
with _.log with all the stuff I want to plop into 
it.

I could approach the callback; however I'm still new to ansible so 
hesitating before hopping into more 'advanced' features.
I don't believe group_vars:all will work because the playbook name isn't 
tied to the host groups.
Passing in the name as an extra-var on the command line reduces usability.
So far the best that I could do is manually define the var in the playbook 
when calling the role. However, it then only exists for that specific play. 



- name: MHE Dematic Conveyer Configuration
  hosts: "{{ target }}"
  vars:
playbook_name: "pb_MA_WMOS_Post_Install_Config"
  roles:
  - { role: role_mhe_config_lower, when: "'Lower_Envs' in group_names", tags
: ["Lower_Envs"] }
  - { role: role_mhe_config_upper, when: "'Upper_Envs' in group_names", tags
: ["Upper_Envs"] }


Or, perhaps I'm just looking at this all wrong and restricting too much 
down one path. Thoughts?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To 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/01de0105-bc9d-4efc-a4da-4f62ebc87ee5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] From within a role, call another role and pass variables at runtime?

2016-11-05 Thread burns498
Hello - 

Can Ansible call a role from within another role, as if it's calling a 
function? Could that other role be passed certain variables at runtime?

I have a few tasks that are repeated several times in my plays. Right now, 
I just copy/paste the same task and tweak an object or two as needed. 
However, if I want to change something about that repeated task I then have 
to find all the places I put it in order for it to change. Also, the 
repeated tasks pollute the readability of the task yaml. It lacks 
modularity. 

I dropped some sample code at the end. The yellow items pull the md5 of two 
files for comparison, so I can take certain actions if they don't match. The 
blue items are logged results, wherein I may want to tweak the content 
later to match changing demands. Could I split out these functions into 
their own roles (with passed variables) and call them within a certain 
play? I could then have one task with pseudo code "Call role md5 
compare(filepath, filename)" and "Call role md5 logging(copy_output)". 

I'm new to Ansible and still getting my feet wet. Open to any suggestions. 
Thank you! :)

Sample Code:
---
- name: Stage MHE wm.properties file from template
  template:
src=wm.properties.j2
dest="{{ staged_config_dir }}/{{ inventory_hostname_short 
}}/wm.properties"
backup=yes

- name: Calculate md5 of staged config
  stat: path="{{ staged_config_dir }}/{{ inventory_hostname_short 
}}/wm.properties"
  register: staged_stat

- name: Calculate md5 of target file
  stat: path="{{ WM_Home 
}}/distribution/DeploymentDirector/installer/properties/wm.properties"
  register: target_stat

- name: deploy staged wm.properties file when diff than target
  copy:
src: "{{ staged_config_dir }}/{{ inventory_hostname_short 
}}/wm.properties"
dest: "{{ WM_Home 
}}/distribution/DeploymentDirector/installer/properties/wm.properties"
backup: yes
remote_src: yes
  register: wm_properties_copy
  when: staged_stat.stat.md5!=target_stat.stat.md5

- name: log deployed changes
  copy:
content: "UPDATED wm.properties!\nSource file: {{ 
wm_properties_copy.src }}\nNew file: {{ wm_properties_copy.dest }}\nBackup 
file: {{ wm_properties_copy.backup_file }}"
dest: "{{ staged_config_dir }}/{{ inventory_hostname_short }}/diff.txt"
  when: staged_stat.stat.md5!=target_stat.stat.md5

- name: Stage MHE ILSStartup.def.xml file from template
  template:
src: ILSStartup.def.xml.j2
dest: "{{ staged_config_dir }}/{{ inventory_hostname_short 
}}/ILSStartup.def.xml"
backup: yes

- name: Calculate md5 of staged ILSStartup.def.xml
  stat: path="{{ staged_config_dir }}/{{ inventory_hostname_short 
}}/ILSStartup.def.xml"
  register: staged_stat

- name: Calculate md5 of target ILSStartup.def.xml
  stat: path="{{ WM_Home 
}}/distribution/DeploymentDirector/installer/templates/ILSStartup.def.xml"
  register: target_stat

- name: deploy staged ILSStartup.def.xml file when diff than target
  copy:
src: "{{ staged_config_dir }}/{{ inventory_hostname_short 
}}/ILSStartup.def.xml"
dest: "{{ WM_Home 
}}/distribution/DeploymentDirector/installer/templates/ILSStartup.def.xml"
backup: yes
remote_src: yes
  register: ILSStartup_def_xml_copy
  when: staged_stat.stat.md5!=target_stat.stat.md5

- name: log ILSStartup.def.xml diff results
  copy:
content: "UPDATED ILSStartup.def.xml!\nSource file: {{ 
ILSStartup_def_xml_copy.src }}\nNew file: {{ ILSStartup_def_xml_copy.dest 
}}\nBackup file: {{ ILSStartup_def_xml_copy.backup_file }}"
dest: "{{ staged_config_dir }}/{{ inventory_hostname_short 
}}/ILS_diff.txt"
  when: staged_stat.stat.md5!=target_stat.stat.md5



Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To 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/7ffdeb60-aea4-4219-b295-0b633a082a9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Inconsistent regex search results in where conditional?

2016-11-03 Thread burns498
Hello - I am working through some seemingly inconsistent results for regex 
search results in where clauses. 

I'm trying to take actions when stdout contains a certain regex pattern. I 
have one method using shell module, and now testing using a preferred 
expect module that I'm trying to get to work. The shell method properly 
logs based on the when-search conditional. The expect skips the same 
conditional, despite writing output for the same script. Below I have 
pasted the play, code, and both outputs for reference. 

I'm new to Ansible, so perhaps I'm missing something obvious. I would 
expect that both conditionals would pass, but that doesn't seem to be the 
case. Thoughts?

*Play:*

[/opt/wmspt]$ ansible-playbook pb_mhe.yml --tags="db","db_expect"

PLAY [MHE Config] 
**

TASK [setup] 
***
ok: [target]

TASK [role_mhe : Database SELECT Ansible Testing] 
**
changed: [target]

TASK [role_mhe : Log SELECT database output] 
***
changed: [target -> localhost]

TASK [role_mhe : Database expect module sqlplus testing] 
***
changed: [target]

TASK [role_mhe : Log EXPECT output] 

skipping: [target]

PLAY RECAP 
*
target  : ok=4changed=3unreachable=0failed=0   


[/opt/wmspt]$ 

*Code:*

- name: Database SELECT Ansible Testing
  tags: db
  shell: ". ~/.profile;sqlplus  
@/manh/software/distribution/ansible_db_select_test.sql"
  register: db_select_output


- name: Log SELECT database output
  tags: db
  local_action: copy content="{{ db_select_output.stdout }}" dest={{ 
log_dir }}/WM_db_select_{{ inventory_hostname }}-{{ lookup('pipe', 'date 
+%Y%m%d%H%M%S') }}.log
  when: db_select_output.stdout | search("[-]+\n[\s]*0\n")


- name: Database expect module sqlplus testing
  tags: db_expect
  expect:
command: "/bin/bash"
responses:
  \$ $:
- . ~/.profile
- sqlplus 
- exit
  SQL> $:
- "@/manh/software/distribution/ansible_db_select_test.sql"
- quit
timeout: 5
echo: yes
  register: expect_output


- name: Log EXPECT output
  tags: db_expect
  local_action: copy content="{{ expect_output.stdout }}" dest={{ log_dir 
}}/WM_expect_{{ inventory_hostname }}-{{ lookup('pipe', 'date 
+%Y%m%d%H%M%S') }}.log
  when: expect_output.stdout | search("[-]+\n[\s]*0\n")



*Shell module output:*

SQL*Plus: Release 12.1.0.2.0 Production on Thu Nov 3 15:09:25 2016

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

Last Successful login time: Thu Nov 03 2016 14:51:18 -05:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage 
Management, OLAP,
Advanced Analytics and Real Application Testing options


 USE_HTTPS
--
0

Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 
- 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage 
Management, OLAP,
Advanced Analytics and Real Application Testing options

*Expect module output (with when conditional commented out):*
[/opt/wmspt]$ . ~/.profile
[/opt/wmspt]$ sqlplus 

SQL*Plus: Release 12.1.0.2.0 Production on Thu Nov 3 15:09:27 2016

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

Last Successful login time: Thu Nov 03 2016 15:09:25 -05:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage 
Management, OLAP,
Advanced Analytics and Real Application Testing options

SQL> @/manh/software/distribution/ansible_db_select_test.sql

 USE_HTTPS
--
0

Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 
- 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage 
Management, OLAP,
Advanced Analytics and Real Application Testing options
[/opt/wmspt]$ exit
exit

-- 
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/1134bb53-6bfc-4605-895f-3fdfab0dbfbd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.