title: Configure Ansible playbook to skip Jenkins Initial setup
body: <p>Hello I'm new to writing Ansible Playbooks but I'm trying to have my playbook install Jenkins. It installs Jenkins just fine but the issue becomes that it wants me to do the initial unlock before installing plugins, creating jobs etc. I've seen in here a few times people saying you just need to add this to your playbook and you should be good. When I add it and then run the playbook it still has this issue even if I do it from a brand new server. Wondering what everyone has done to get by this issue. Thanks for your assistance!</p>
  <p>Code I've seen from other posts:
  <a href="https://stackoverflow.com/questions/42219781/gets-error-cannot-get-csrf-when-trying-to-install-jenkins-plugin-using-ansible">Gets error &quot;Cannot get CSRF&quot; when trying to install jenkins-plugin using ANSIBLE</a></p>
  <pre><code>- name: Jenkins Skip startUp for MI
    lineinfile:
      dest=/etc/sysconfig/jenkins
      regexp='^JENKINS_JAVA_OPTIONS='
      line='JENKINS_JAVA_OPTIONS=&quot;-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false&quot;'
    register: result_skip_startup_wizard
  </code></pre>
  <p>My Playbook</p>
  <pre><code>---
  # jenkins
  
  - name: Create jenkins group
    group:
      name: jenkins
      state: present
  
  - name: Create jenkins user
    user:
      name: jenkins
      group: jenkins
      state: present
  
  - name: Import jenkins gpg key
    rpm_key:
      state: present
      key: http://pkg.jenkins.io/redhat-stable/jenkins.io.key
      validate_certs: no
  
  - name: Download Jenkins repo
    get_url:
      url: http://get.jenkins.io/redhat-stable/jenkins-2.332.3-1.1.noarch.rpm
      dest: /etc/yum.repos.d/
  
  - name: Install java
    yum:
      name: java-11-openjdk
      state: present
  
  - name: Install Jenkins
    package:
      name: /etc/yum.repos.d/jenkins-2.332.3-1.1.noarch.rpm
      state: latest
  
  - name: Jenkins Skip startUp for MI
    lineinfile:
      dest=/etc/sysconfig/jenkins
      regexp='^JENKINS_JAVA_OPTIONS='
      line='JENKINS_JAVA_OPTIONS=&quot;-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false&quot;'
    register: result_skip_startup_wizard
  
  - name: Start and Enable Jenkins
    systemd:
      name: jenkins
      state: started
      enabled: true
  
  - name: Sleep for 30 seconds and continue with Jenkins buildout
    wait_for: timeout=30
  
  </code></pre>
  <p>For reference this is what I see in the server when I check the file and then when I just grep for the process.
  jenkins     8474       1 34 18:29 ?        00:00:20 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080</p>
  <p>You can see the changes though do get put in the file as mentioned from above. Which makes me think even after restarting the service its not seeing the new option. I even manually stopped jenkins and then started but it still did not pick it up.</p>
  <p>JENKINS_JAVA_OPTIONS=&quot;-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false&quot;</p>