8

i'm trying to add a value in inline module in sysctl.conf file, how can i achieve that? once i enter the value in the prompt it should be updated in the sysctl.conf file.

- name: shmmax
      prompt: " Please enter the value for kernel.shmmax "
      private: false


- name: Set some kernel parameters
      lineinfile:
        dest: /etc/sysctl.conf
        regexp: "{{ item.regexp }}"
        line: "{{ item.line }}"
      with_items:
        - { regexp: '^kernel.shmmax', line: 'kernel.shmmax = {{ shmmax }}' }


error is get is.

TASK [Set some kernel parameters] **********************************************************************************************************************************
fatal: [192.168.1.28]: FAILED! => {"msg": "'kernel' is undefined"}
        to retry, use: --limit `enter code here`

Thank you

1 Answer 1

13

There is the pause module to prompt for an input inside a task.

For example

    - hosts: localhost
      tasks:
        - pause:
            prompt: "Please enter the value for kernel.shmmax "
            echo: yes
          register: result
        - set_fact:
            shmmax: "{{ result.user_input }}"
        - debug:
            var: shmmax

gives (abridged)

    TASK [pause] 
    [pause]
    Please enter the value for kernel.shmmax :
    [ok: [localhost]
    TASK [set_fact]
    ok: [localhost]
    TASK [debug] 
    ok: [localhost] => {
        "shmmax": "new_kernel.shmmax_value"
    }

Notes

  1. This part of the code from the question can't work because there is no module in the task
    - name: shmmax
          prompt: " Please enter the value for kernel.shmmax "
          private: false

Running such code would produce

    ERROR! Syntax Error while loading YAML.
      mapping values are not allowed in this context
  1. A variable can be used in any task after it has been prompted for, registered, and declared with set_fact.
1
  • Thank you!! it worked. is it set_fact does the trick? because ive other prompts as well which worked fine. but thet are not present in regex.
    – snehal s
    May 28, 2019 at 12:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .