[ansible-project] Re: List of running processes form multiple linux hosts using with_items

2018-04-13 Thread smitconsultant2017
HI Bishwajit Samanta

Thanks. It is creating file for each hostname but data is not in readable 
format. Are you able to do favor little more, how to get the data in each 
file as orignal form like as processes list show on linux machine? I was 
initially thinking to get output from all hosts in one file and somehow get 
processes list along with hostname one by one. But this can work as well. 
Many Thanks.



On Thursday, April 12, 2018 at 5:09:41 PM UTC+10, Bishwajit Samanta wrote:
>
> I just changed the host as devops
> ---
>
> - hosts: devops
>   gather_facts: no
>   tasks:
> - name: Get the running process across the systems
>   command: ps -ef
>   register: output
>
> - name: Getting some details of systems
>   local_action: copy content={{ output }} dest=/opt/{{ 
> inventory_hostname }}file
>
> Output::-
> -
>
> [root@ansible-master opt]# ls
> 192.168.56.111file  192.168.56.116file 
>
> You can try with this and see if your problem get resolved.
>
> On Wednesday, April 11, 2018 at 1:42:45 PM UTC+5:30, 
> smitconsu...@gmail.com wrote:
>>
>> Hi 
>> I am trying to achieve all running processes on our linux machines via 
>> ansible and get output in a file along with each host name and processes. I 
>> have made below playbook but not getting to the point how to get list of 
>> processes for each host one by one and store in a file. Can anyone please 
>> help with the code how can I achieve this? I am using with_items with list 
>> of hosts which is coming from inventory group hostlist. many thanks
>>
>> ---
>> - hosts: all
>>   gather_facts: false
>>   tasks:
>>
>>   - name: Get Running Processes
>> command: ps -ef
>> delegate_to: "{{ item }}"
>> run_once: false
>> with_items:
>>  - "{{ groups['hostlist'] }}"
>> register: process_list
>>
>>
On Thursday, April 12, 2018 at 5:09:41 PM UTC+10, Bishwajit Samanta wrote:
>
> I just changed the host as devops
> ---
>
> - hosts: devops
>   gather_facts: no
>   tasks:
> - name: Get the running process across the systems
>   command: ps -ef
>   register: output
>
> - name: Getting some details of systems
>   local_action: copy content={{ output }} dest=/opt/{{ 
> inventory_hostname }}file
>
> Output::-
> -
>
> [root@ansible-master opt]# ls
> 192.168.56.111file  192.168.56.116file 
>
> You can try with this and see if your problem get resolved.
>
> On Wednesday, April 11, 2018 at 1:42:45 PM UTC+5:30, 
> smitconsu...@gmail.com wrote:
>>
>> Hi 
>> I am trying to achieve all running processes on our linux machines via 
>> ansible and get output in a file along with each host name and processes. I 
>> have made below playbook but not getting to the point how to get list of 
>> processes for each host one by one and store in a file. Can anyone please 
>> help with the code how can I achieve this? I am using with_items with list 
>> of hosts which is coming from inventory group hostlist. many thanks
>>
>> ---
>> - hosts: all
>>   gather_facts: false
>>   tasks:
>>
>>   - name: Get Running Processes
>> command: ps -ef
>> delegate_to: "{{ item }}"
>> run_once: false
>> with_items:
>>  - "{{ groups['hostlist'] }}"
>> register: process_list
>>
>>
On Thursday, April 12, 2018 at 5:09:41 PM UTC+10, Bishwajit Samanta wrote:
>
> I just changed the host as devops
> ---
>
> - hosts: devops
>   gather_facts: no
>   tasks:
> - name: Get the running process across the systems
>   command: ps -ef
>   register: output
>
> - name: Getting some details of systems
>   local_action: copy content={{ output }} dest=/opt/{{ 
> inventory_hostname }}file
>
> Output::-
> -
>
> [root@ansible-master opt]# ls
> 192.168.56.111file  192.168.56.116file 
>
> You can try with this and see if your problem get resolved.
>
> On Wednesday, April 11, 2018 at 1:42:45 PM UTC+5:30, 
> smitconsu...@gmail.com wrote:
>>
>> Hi 
>> I am trying to achieve all running processes on our linux machines via 
>> ansible and get output in a file along with each host name and processes. I 
>> have made below playbook but not getting to the point how to get list of 
>> processes for each host one by one and store in a file. Can anyone please 
>> help with the code how can I achieve this? I am using with_items with list 
>> of hosts which is coming from inventory group hostlist. many thanks
>>
>> ---
>> - hosts: all
>>   gather_facts: false
>>   tasks:
>>
>>   - name: Get Running Processes
>> command: ps -ef
>> delegate_to: "{{ item }}"
>> run_once: false
>> with_items:
>>  - "{{ groups['hostlist'] }}"
>> register: process_list
>>
>>
On Thursday, April 12, 2018 at 5:09:41 PM UTC+10, Bishwajit Samanta wrote:
>
> I just changed the host as devops
> ---
>
> - hosts: devops
>   gather_facts: no
>   tasks:
> - name: Get the running process across the systems
>   command: ps -ef
>   register: output
>
> - name: Getting some details of systems
>   

[ansible-project] List of running processes form multiple linux hosts using with_items

2018-04-11 Thread smitconsultant2017
Hi 
I am trying to achieve all running processes on our linux machines via 
ansible and get output in a file along with each host name and processes. I 
have made below playbook but not getting to the point how to get list of 
processes for each host one by one and store in a file. Can anyone please 
help with the code how can I achieve this? I am using with_items with list 
of hosts which is coming from inventory group hostlist. many thanks

---
- hosts: all
  gather_facts: false
  tasks:

  - name: Get Running Processes
command: ps -ef
delegate_to: "{{ item }}"
run_once: false
with_items:
 - "{{ groups['hostlist'] }}"
register: process_list

-- 
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/34297f23-0ef1-47d1-bb98-2730a9079424%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Ansible Jinja2 filter error Rhel 7.4

2018-04-09 Thread smitconsultant2017
Hi
I am trying to run below playbook to find the server (openstack host), on 
which vm will be running using jinja2 filter but getting error no test 
named 'equalto'. After googling found some ppl suggested upgrade jinja2 and 
I am using version 2.7 on RHEL which is latest for RHEL. I was able to 
somehow make this playbook work once but not sure how which proved that 
code is working. I am struggling since then but have no luck yet. I found 
compatibility issue on bugzilla between this jinja2 ver and ansible/ansible 
Tower? Can Anyone suggest what other filter or way I can choose to achieve 
this which works on below jinja2 version? Thanks

Playbook:

- hosts: localhost
  vars:
   openstack: [reg1, reg2, reg3, reg4]

  tasks:
- name: Command to find os server where vm exists
  shell: somecommand-to-check-if-vm-exist | wc -l
  delegate_to: "{{ item }}"
  with_items: "{{ openstack }}"
  register: vm_check

- name: set fact
  set_fact:
os_server: "{{ (vm_check.results | selectattr('stdout','equalto','1') | 
list | first }}"

- name: debug var
  debug:
msg: "{{ os_server }}"

Error below:

"msg": "Unexpected failure during module execution.", "exception": 
"Traceback File \"/usr/lib/python2.7/site-packages/jinja2/environment.py\", 
line 438, in call_test\n raise TemplateRuntimeError('no test named %r' % 
name)\nTemplateRuntimeError: no test named 'equalto'\n", "stdout": "" }
ansible --version ansible 2.4.3.0

ansible Tower ver: < Tower 3.2.3 >

python version = 2.7.5 (default, May 3 2017, 07:55:04) [GCC 4.8.5
I am using RHEL 7. 
rpm -q python-jinja2 
python-jinja2-2.7.2-2.el7.noarch

-- 
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/9108a890-b325-4061-b6b7-f4a6bbc52238%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Ansible Tower Job Output via api

2018-02-26 Thread smitconsultant2017
Hi 

I am looking for a way to get output of ansible tower job. I was looking at 
rest Api v 2 and can see jobs and templates. The aim is to run the job in 
tower and if failed send the output in email as part of master playbook. I 
could not find out how to get output of the job currently running and how 
should I define it in my playbook at fail. I know you can find job output 
if you know job id and you can use tower/api/v2/jobs/job-id. Has anyone 
used this feature and know how can I achieve it? Thanks

Regards,

-- 
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/7fae768c-4a83-4164-b690-f3f87ff7ffdf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Ansible multiple roles in a block with rescue/fail

2018-02-22 Thread smitconsultant2017


Hi,

I am trying to create a master playbook where I am including multiple roles 
in it. I am using block for each role in playbook along with rescue and 
fail section. Rescue section should perform rollback of the previous 
completed role and should fail playbook after rolling back and email failed 
details. I tried rescue section and it works but playbook does not fail and 
continue to next role. I tried fail inside rescue section that does not 
work as well. I can create fail task after completion of every block to 
fail the playbook but not sure how to register previous role's results. Can 
anyone help how to achieve this? Also, for email I was thinking to register 
the output of block in a var and send as email but register does not work 
with block. I appreciate your help. Thanks
--

- hosts: all

  gather_facts: false

  vars:

  pre_tasks:

- include_vars: 'vars.yml' 

- include_vars: 'vault1.yml' 

  tasks: 

- name Role1

  -  include_role:
  name: role1

- name: Role2

 block:
  - include_role:

 name: role2

 vars:

vm: create
 # - fail: 

  #  msg: "Error: Role1 failed.” 

rescue: 
 - fail: 
 - name: Debug msg 
   debug: msg="Error:Role 1 failed..Rolling back role1."


 - include_role:

   name: remove_role1

-- 
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/0f22f1ed-ec4c-4c4c-8693-c258e0358dad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.