[ansible-project] Re: ansible regex with lineinfile module not updating all host

2018-04-04 Thread rraka1002
Ah! that works John! thnx a mile.

On Thursday, April 5, 2018 at 1:41:14 AM UTC+5:30, John Harmon wrote:
>
> You need to account for white space. Try:
>
> regexp: '^passwd:.*files ldap'
>
>
>
>

-- 
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/2f6c48b5-372a-480f-ab42-dee7b05cf4fe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] ansible regex with lineinfile module not updating all host

2018-04-04 Thread rraka1002


Esteemed Collegues, I have created a Playbook to replcae the Entry in a 
file using a lineinfile module, while i tried running it run and replace in 
entry on the one host while not on the another host, i don't understand 
why? as it doesn't report any error even on the debug mode. Do i need to 
have some another regex pattern.

---
- name: Playbook to replace the line in file
  hosts: all
  remote_user: root
  gather_facts: False
  serial: 4
  tasks:
- name: replace line
  lineinfile:
dest: /tmp/test_master
state: present
regexp: '^passwd: files ldap' #  line to be replaced
line: 'passwd_compat: ldap'   #  new line which is replace existing , 
the one above
backrefs: yes
backup: yes
  register: nss

- name: replace line
  debug: var=nss



My Hostvar Inventory File:

# test_regex_hosts
[hosts]
Dev-mauj
Dev-pranjala
[hosts:vars]
ansible_ssh_user=root
ansible_ssh_private_key_file=/Dev/ansibleSpotin

Destination File contents:

$ cat /tmp/test_master
#
# nsswitch.conf
#
passwd: files ldap
shadow: files ldap
group:  files ldap
hosts:  files dns
bootparams: files
ethers: files
netmasks:   files ldap
networks:   files ldap
protocols:  files ldap
rpc:files ldap
services:   files ldap
netgroup:   files ldap
publickey:  files ldap
automount:  files ldap
printers:   user files ldap
sudoers:ldap
aliases:files ldap

Note: ansible 2.4

-- 
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/6ab8d218-03d0-4fc5-bef4-98153772252b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] reboot via ansible 2.4

2018-03-15 Thread rraka1002
Thanks JYL, by the way there is no log when i run this play , even system 
gets rebooted and up  but it doesn't  give any clue and breaks the 
connection .
Anyway, i will try to debug the logs..


On Thursday, March 15, 2018 at 9:03:45 PM UTC+5:30, Jean-Yves LENHOF wrote:
>
> Hi, 
>
>
> Le 15/03/2018 à 15:21, rrak...@gmail.com  a écrit : 
> > Hello Friends,  
> > 
> > Does anyone have experience using the reboot playbook on RHEL systems, 
> > i'm using below method and it reboots the systems but in between while 
> > system is rebooting it breaks the connection and does not wait for 
> > post reboot status like uptime, if someone already overcomed this 
> > please let me know , my play looks like below... 
> > 
> > --- 
> > - name: Reboot a host and wait for it to return 
> >   hosts: postinstall 
> >   remote_user: root 
> > 
> >   tasks: 
> > - name: check automount 
> >   service: name=autofs state=stopped 
> > 
> > - name: reboot host 
> >   shell: sleep 10 && /sbin/shutdown -r now 
> >   async: 360 
> >   poll: 0 
> >   become: true 
>
> Without any log of what's the problem exactly is, it's not so obvious to 
> help you... Did you try to add a sleep just after the shutdown (on the 
> shell line) like written in this article ? 
>
> https://stackoverflow.com/questions/23877781/how-to-wait-for-server-restart-using-ansible
>  
>
> > 
> > - name: waiting for server booting up 
> >   local_action: wait_for host="{{ inventory_hostname }}" port=22 
> > delay=5 timeout=360 
> >  
> >
> > - name: check uptime 
> >   local_action: shell ansible -u {{ ansible_user_id }} -m ping {{ 
> > inventory_hostname }} 
> >   register: result 
> >   until: result.rc == 0 
> >   retries: 30 
> >   delay: 10 
>
> Why using shell to do an ansible ping ? 
> You can use it directly Try to always avoid shell module 
>
> > 
> > # And finally, execute 'uptime' when the host is back. 
> > - shell: uptime 
>
> There's a fact for this : 
> ansible_uptime_seconds 
> Why not using it ? 
>
> Regards, 
>
> JYL 
>
>

-- 
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/e0fd912c-87f0-45c6-bbec-4328bfc9932c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] reboot via ansible 2.4

2018-03-15 Thread rraka1002
Hello Friends, 

Does anyone have experience using the reboot playbook on RHEL systems, i'm 
using below method and it reboots the systems but in between while system 
is rebooting it breaks the connection and does not wait for post reboot 
status like uptime, if someone already overcomed this please let me know , 
my play looks like below...

---
- name: Reboot a host and wait for it to return
  hosts: postinstall
  remote_user: root

  tasks:
- name: check automount
  service: name=autofs state=stopped

- name: reboot host
  shell: sleep 10 && /sbin/shutdown -r now
  async: 360
  poll: 0
  become: true

- name: waiting for server booting up
  local_action: wait_for host="{{ inventory_hostname }}" port=22 
delay=5 timeout=360

  
- name: check uptime
  local_action: shell ansible -u {{ ansible_user_id }} -m ping {{ 
inventory_hostname }}
  register: result
  until: result.rc == 0
  retries: 30
  delay: 10

# And finally, execute 'uptime' when the host is back.
- shell: uptime

-- 
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/ae6d87f1-5439-4f66-b4c7-d10e1057ff72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Is there any Ansible master / Slave concept.

2018-03-12 Thread rraka1002
Thanks for teh information @Brian, Can you point any link to over for 
Tower/AWX  you just mentioned.

On Monday, March 12, 2018 at 9:48:08 PM UTC+5:30, Brian Coca wrote:
>
> We try to avoid slavery in all contexts  that said there is a 
> 'controller' vs 'target' concept and when using ansible-pull you have 
> 'server' vs 'client'. 
>
> If you look at Tower/AWX you have other ways of clustering the control 
> nodes. 
>
>
>
> -- 
> -- 
> 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/58a907b2-faff-4641-a6ee-8be6a9433478%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] How to Pick and match the inventory_hostname against {{ ansible_hostname }} using groups.hosts

2018-03-12 Thread rraka1002
@Brian ,  Thanks a lot for your suggestion, this looks Great,

What about "when: inventory_hostname == groups.hosts"  when: 
inventory_hostname == groups.hosts[0] , i google around but did not get 
clear & explicit explanation about its usage

On Monday, March 12, 2018 at 9:02:11 PM UTC+5:30, Brian Coca wrote:
>
> First of all you are comparing a string (inventory_hostname) to a list 
> (groups.hosts, which is [host-test1, host-test2, noi-pranjala]). 
>
> if you want to match inventory-hostname to ansible_hostname, just do that: 
>
>
> when: inventory_hostname == ansible_hostname 
>
>
> that will skip the task when they don't match. 
>
>
> if you want the task to actually fail: 
>
>
> failed_when: inventory_hostname != ansiblie_hostname 
>
>
> -- 
> 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/ca01ad77-4c40-4f5e-8162-32636a1c7a6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] How to Pick and match the inventory_hostname against {{ ansible_hostname }} using groups.hosts

2018-03-12 Thread rraka1002
Hi Experts,


---
- hosts: all
  remote_user: root
  tasks:
  - name: test variable
shell: echo "setosprov-04.sh -o OSLABEL -b SITE hostinfo={{ 
ansible_hostname }}:{{ ansible_default_ipv4.address }} CIC0" 
#when: inventory_hostname == "{{ inventory_hostname }}"
when: inventory_hostname == groups.hosts

My hostvar inventory as below:

[hosts]
host-test1
host-test2
noi-pranjala
[hosts:vars]
ansible_ssh_user=root


Now i'm checking where "{{ ansible_hostname }}" should match the each   "{{ 
inventory_hostname }}"  and if  "{{ inventory_hostname }}" matches with  
"{{ ansible_hostname }}"  then proceed otherwise fail.

I tried using "when: inventory_hostname == groups.hosts"  it didn't pich 
the hostnames Serially hence its getting failed, So, how to ensure the each 
"{{ inventory_hostname }}"  can be red serially so it can run to all the 
hosts in a sequence so it may match the hostname correctlt and compare the 
condition.

-- 
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/ff296687-a196-4494-9852-7df44a4f0207%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] pick the hostname dynamically from facts and match with inventory hostname and if matched then run the command

2018-03-07 Thread rraka1002
Thanks Kai.

On Wednesday, March 7, 2018 at 12:17:34 PM UTC+5:30, Kai Stian Olstad wrote:
>
> On Wednesday, 7 March 2018 06.31.27 CET rrak...@gmail.com  
> wrote: 
> > I'm looking for an idea to spill the hostname infromation geting from 
> facts 
> > and run the command if the matches the hostname provided in inventory. 
> > Saying that "myhostname" value should be picked & matched from inventory 
> > ones and get the IP of the hostname once matched to complete the command 
>
> A good start i this 
> https://docs.ansible.com/ansible/latest/playbooks_variables.html 
> 
>  
>
>
> > My Host inventory: 
> > 
> > test-host1 
> > test-host2 
>
> Try running ansible ad-hoc to see what facts you have available 
> ansible test-host1 -m setup 
> and/or 
> ansible localhost -m setup 
>
>
> > somecommand hostinfo=myhostname:IP_ADDRESS  
> > somecommand hostinfo=test-host1:xx.xx.xx.xx CIC01 
> > 
> > Exaplaination: 
> > 
> > somecommand = Static Value 
> > hostinfo = Static Value 
> > myhostname = Should be the same as taken from inventory 
>
> {{ inventory_hostname }} 
>
>
> > IP_ADDRESS = Should be the IP of Hostname taken from invetory 
>
> There are different once, check with the ad-hoc command above. 
> One is {{ ansible_default_ipv4.address }} 
>
>
> -- 
> 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/c0bef543-a91c-461f-9ac5-195fc3505ad1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Ansible Mail Module Failing

2018-03-06 Thread rraka1002
@Simon, So whenyou run `ansible-playbook --syntax-check mail.yml`  does it 
gives some error code?
i tried that with ansible version 2.4 and it works as expected

On Tuesday, March 6, 2018 at 8:39:52 PM UTC+5:30, Simon Hayes wrote:
>
> I'm running a simple playbook to report on server configurations which is 
> formatted into an html file from a template.  I use the mail module to 
> attach the html file into the body of the mail as follows:
>
>
>
>
>
>
>
>
>
>
>
>
> *- hosts: localhost  tasks:- name: Send e-mail  local_action: 
> mailport=25headers="Content-type=text/html"
> subtype=htmlfrom="x...@xxx.com "
> to="x...@xxx.com "subject='Server Report'
> body="{{ lookup('file', '/tmp/report.html') }}"*
>
> When I run this on a group of 13/14 servers the play runs fine, mail is 
> sent and received as expected.  If I add more servers to the group, the 
> initial parts of the playbook run fine, but then it fails when attempting 
> to send the mail.  I've not seen this with any other playbooks or roles I 
> have on the same server, emails seem to send out just fine
>
>
>
> *TASK [Send e-mail] 
> ***An
>  
> exception occurred during task execution. To see the full traceback, use 
> -vvv. The error was: socket.error: [Errno 111] Connection refusedfatal: 
> [localhost -> localhost]: FAILED! => {"changed": false, "module_stderr": 
> "Traceback (most recent call last):\n  File 
> \"/tmp/ansible_TNdcry/ansible_module_mail.py\", line 386, in \n
> main()\n  File \"/tmp/ansible_TNdcry/ansible_module_mail.py\", line 257, in 
> main\ncode, smtpmessage = smtp.connect(host, port=port)\n  File 
> \"/usr/lib64/python2.6/smtplib.py\", line 300, in connect\nself.sock = 
> self._get_socket(host, port, self.timeout)\n  File 
> \"/usr/lib64/python2.6/smtplib.py\", line 278, in _get_socket\nreturn 
> socket.create_connection((port, host), timeout)\n  File 
> \"/usr/lib64/python2.6/socket.py\", line 567, in create_connection\n
> raise error, msg\nsocket.error: [Errno 111] Connection refused\n", 
> "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1}*
>
> /var/log/messages shows the following abrtd errors which appear to come 
> from python and ansible_module_mail.py:
>
>
>
> *Mar  5 17:45:13  abrt: [ID - user.info 
> ]  detected unhandled Python exception in 
> '/tmp/ansible_TNdcry/ansible_module_mail.py'Mar  5 17:45:14 
>  abrtd: [ID - daemon.err]  Directory 
> 'pyhook-2018-03-05-17:45:14-17875' creation detectedMar  5 17:45:14 
>  abrt-server[18081]: [ID - daemon.err]  Saved Python 
> crash dump of pid 17875 to /var/spool/abrt/pyhook-2018-03-05-17:45:14-17875*
>
> What I don't know is whether this is ansible and/or python, or perhaps my 
> poor implementation of the mail module.  Google search has not returned any 
> worthy suggestions or causes.  Could I be missing something server side - 
> python config or sendmail?
> Does anyone have any ideas?
>
> Version information:
>
>  
>
>
>
>
> * ansible 2.4.3.0  config file = /etc/ansible/ansible.cfg  configured 
> module search path = [u'/root/.ansible/plugins/modules', 
> u'/usr/share/ansible/plugins/modules']  ansible python module location = 
> /usr/lib/python2.6/site-packages/ansible  executable location = 
> /usr/bin/ansible  python version = 2.6.6 (r266:84292, Aug  9 2016, 
> 06:11:56) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]*
>
> -Simon
>

-- 
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/93303546-d190-40b8-a2e8-29978770f313%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] pick the hostname dynamically from facts and match with inventory hostname and if matched then run the command

2018-03-06 Thread rraka1002
I'm looking for an idea to spill the hostname infromation geting from facts 
and run the command if the matches the hostname provided in inventory.
Saying that "myhostname" value should be picked & matched from inventory 
ones and get the IP of the hostname once matched to complete the command 
My Host inventory:

test-host1
test-host2


somecommand hostinfo=myhostname:IP_ADDRESS 
somecommand hostinfo=test-host1:xx.xx.xx.xx CIC01

Exaplaination:

somecommand = Static Value
hostinfo = Static Value
myhostname = Should be the same as taken from inventory
IP_ADDRESS = Should be the IP of Hostname taken from invetory
CMD_ARGS = Static Value ( like i mentioned CIC01)


- name: Ansible to get the resolv.conf output
  hosts: all
  remote_user: root
  gather_facts: True
  tasks:
  - name: runing re-image
shell: somecommand hostinfo=test-host1:xx.xx.xx.xx CIC01
 
register: named

  - name: Storing the remote Hosts Output locally 
lineinfile: create=yes dest=/opt/out.logs  line="{{ named.stdout }}"
delegate_to: 127.0.0.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/b7767b1e-6800-4044-b301-44a89eb97fe7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.