update /etc/cron.allow on multiple nodes diff values

16 views
Skip to first unread message

Kiran Kumar

unread,
Jan 24, 2017, 6:31:35 PM1/24/17
to Ansible Project
hello all

i need to update  /etc/cron.allow  on many servers

below is eg

x oracle
y db
x prod
...
..




===

it works for a single node 

- name: Add a word in remote file
  hosts: temp
  remote_user: xx
  sudo: yes
  tasks:
    - name: edit cron.allow
      lineinfile:
       destfile: /etc/cron.allow
       line: 'oracle'


==

how can i do it for huge number of nodes ?

Johannes Kastl

unread,
Jan 25, 2017, 2:31:50 AM1/25/17
to ansible...@googlegroups.com
On 24.01.17 03:30 Kiran Kumar wrote:

> x oracle
> y db
> x prod

I assume the x should be the hostname, and the second column should be
the line in /etc/hosts.allow?

> how can i do it for huge number of nodes ?

You put more than one host in the "- hosts:" line? ;-)

Seriously, put the x=oracle values in the host_vars for each hosts.
Call it something describing, hostname_in_etc_hosts_allow and set it
to oracle on host x (host_vars/x/main.yml), and to db on host y.

Then put the variable hostname_in_etc_hosts_allow in your task:

- name: Add a word in remote file
hosts: temp
remote_user: xx
sudo: yes
tasks:
- name: edit cron.allow
lineinfile:
destfile: /etc/cron.allow
line: '{{ hostname_in_etc_hosts_allow }}'

Johannes

BTW: "sudo: yes" is being substituted by "become: yes" and
"become_method: sudo" for quite some time, might throw an error in
future releases.

signature.asc
Reply all
Reply to author
Forward
0 new messages