Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

ansible lineinfile

# NOTE: Before 2.3, option 'dest', 'destfile' or 'name' was used instead of 'path'
- name: Ensure SELinux is set to enforcing mode
  lineinfile:
    path: /etc/selinux/config
    regexp: '^SELINUX='
    line: SELINUX=enforcing

- name: Make sure group wheel is not in the sudoers configuration
  lineinfile:
    path: /etc/sudoers
    state: absent
    regexp: '^%wheel'

- name: Replace a localhost entry with our own
  lineinfile:
    path: /etc/hosts
    regexp: '^127.0.0.1'
    line: 127.0.0.1 localhost
    owner: root
    group: root
    mode: '0644'

- name: Ensure the default Apache port is 8080
  lineinfile:
    path: /etc/httpd/conf/httpd.conf
    regexp: '^Listen '
    insertafter: '^#Listen '
    line: Listen 8080

- name: Ensure we have our own comment added to /etc/services
  lineinfile:
    path: /etc/services
    regexp: '^# port for http'
    insertbefore: '^www.*80/tcp'
    line: '# port for http by default'

- name: Add a line to a file if the file does not exist, without passing regexp
  lineinfile:
    path: /tmp/testfile
    line: 192.168.1.99 foo.lab.net foo
    create: yes

# NOTE: Yaml requires escaping backslashes in double quotes but not in single quotes
- name: Ensure the JBoss memory settings are exactly as needed
  lineinfile:
    path: /opt/jboss-as/bin/standalone.conf
    regexp: '^(.*)Xms(d+)m(.*)$'
    line: '1Xms${xms}m3'
    backrefs: yes

# NOTE: Fully quoted because of the ': ' on the line. See the Gotchas in the YAML docs.
- name: Validate the sudoers file before saving
  lineinfile:
    path: /etc/sudoers
    state: present
    regexp: '^%ADMIN ALL='
    line: '%ADMIN ALL=(ALL) NOPASSWD: ALL'
    validate: /usr/sbin/visudo -cf %s
Comment

PREVIOUS NEXT
Code Example
Shell :: install all dependencies npm 
Shell :: how to install lua on ubuntu 
Shell :: bash see size of directory 
Shell :: docker container name 
Shell :: how do I list all my packages on arch linux 
Shell :: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root? 
Shell :: wsl install 
Shell :: how to run exe file with shell 
Shell :: push code to github 
Shell :: remove all files with no extention rm 
Shell :: ls with file size 
Shell :: zsh aliases 
Shell :: install chromedriver linux 
Shell :: edit file as root ubuntu 
Shell :: sudo npm cache clean -f 
Shell :: ubuntu alien install 
Shell :: linux find files ending with 
Shell :: virtualbox kernel driver not installed ubuntu 
Shell :: wsl add directory to path 
Shell :: bash delete folder 
Shell :: volver a commit anterior temporal 
Shell :: create batch file to delete folders 
Shell :: heroku upload local database 
Shell :: kill tomcat ubuntu 
Shell :: ram info unix 
Shell :: git force merge branch 
Shell :: download putty for ubuntu 
Shell :: git force push to remote 
Shell :: vscode safe mode 
Shell :: sed remove line after match 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =