Need help of Ansible lineinfile module with a variable based on hostname

Hi,

I need help of Ansible lineinfile module with a variable based on hostname. Here is what I have for the task:

On server vccs7ap01:

  • name: ulimits - find sidadm on the server
    shell: hostname | sed ‘s/vc//’ | sed ‘s/ap[0-9][0-9]//g’ | sed ‘s/$/adm/’
    register: sidadm

  • name: ulimits - add sidadm soft value to limits file
    lineinfile:
    path: /etc/security/limits.conf
    regexp: ‘^sidadm.stdout\ soft’
    line: “@sidadm.stdout\ soft 65536”

  • name: ulimits - add sidadm hard value to limits file
    lineinfile:
    path: /etc/security/limits.conf
    regexp: ‘^sidadm.stdout\ hard’
    line: “@sidadm.stdout\ hard 65536”

After ran the playbook, change was made to /etc/security/limits.conf:
@sidadm.stdout soft 65536
@sidadm.stdout hard 65536

but I would like to have the entries:
cs7adm soft 65536
cs7adm hard 65536

Thanks in advance.

Frank

Hi,

I need help of Ansible lineinfile module with a variable based on hostname. Here is what I have for the task:>
On server vccs7ap01:

\- name: ulimits \- find sidadm on the server
  shell: hostname | sed 's/vc//' | sed 's/ap\[0\-9\]\[0\-9\]//g' | sed 's/$/adm/'
  register: sidadm

Ansible has already the hostname present in the variable "ansible_hostname", so you can really save the roundtrip to
vccs7ap01:

- name:
  set_fact:
    sidadm: "{{ ansible_hostname | regex_replace('vc') | regex_replace('ap[0-9][0-9]') + 'adm' }}"

\- name: ulimits \- add sidadm soft value to limits file
  lineinfile:
    path: /etc/security/limits\.conf
    regexp: '^sidadm\.stdout\\ soft'
    line: "@sidadm\.stdout\\ soft 65536"

\- name: ulimits \- add sidadm hard value to limits file
  lineinfile:
    path: /etc/security/limits\.conf
    regexp: '^sidadm\.stdout\\ hard'
    line: "@sidadm\.stdout\\ hard 65536"

There is also a dedicated module for adjusting PAM limits, so let's use that:

- name: ulimits - add sidadm soft value to limits file
  pam_limits:
    domain: "{{ sidadm }}"
    limit_type: soft
    limit_item: nofile
    value: "65536"

After ran the playbook, change was made to /etc/security/limits.conf:
@sidadm.stdout soft 65536
@sidadm.stdout hard 65536

but I would like to have the entries:
cs7adm soft 65536
cs7adm hard 65536

Shouldn't that be:

cs7adm soft nofile 65536
cs7adm hard nofile 65536

Regards
         Racke

Thanks a lot for the tip, Racke. It really works.

I really appreciate your help.

Regards

Frank