Posts

Showing posts with the label Centos

Check If Service Exists With Ansible

Answer : See the service_facts module, new in Ansible 2.5. - name: Populate service facts service_facts: - debug: msg: Docker installed! when: "'docker' in services" Of course I could also just check if the wrapper script exists in /etc/init.d. So this is what I ended up with: - name: Check if Service Exists stat: path=/etc/init.d/{{service_name}} register: service_status - name: Stop Service service: name={{service_name}} state=stopped when: service_status.stat.exists register: service_stopped It would be nice if the "service" module could handle "unrecognized service" errors. This is my approach, using the service command instead of checking for an init script: - name: check for apache shell: "service apache2 status" register: _svc_apache failed_when: > _svc_apache.rc != 0 and ("unrecognized service" not in _svc_apache.stderr) - name: disable apache service: name=...

Bash: Mkvirtualenv: Command Not Found

Answer : Solution 1 : For some reason, virtualenvwrapper.sh installed in /usr/bin/virtualenvwrapper.sh , instead of under /usr/local/bin . The following in my .bash_profile works... source "/usr/bin/virtualenvwrapper.sh" export WORKON_HOME="/opt/virtual_env/" My install seems to work fine without sourcing virtualenvwrapper_bashrc Solution 2 : Alternatively as mentioned below, you could leverage the chance that virtualenvwrapper.sh is already in your shell's PATH and just issue a source `which virtualenvwrapper.sh` Try: source `which virtualenvwrapper.sh` The backticks are command substitution - they take whatever the program prints out and put it in the expression. In this case "which" checks the $PATH to find virtualenvwrapper.sh and outputs the path to it. The script is then read by the shell via 'source'. If you want this to happen every time you restart your shell, it's probably better to grab the output from t...

Centos 7 Save Iptables Settings

Answer : Solution 1: Disable firewalld by the following command: systemctl disable firewalld Then install iptables-service by following command: yum install iptables-services Then enable iptables as services: systemctl enable iptables Now you can save your iptable rules by following command: service iptables save Solution 2: CentOS 7 is using FirewallD now! Use the --permanent flag to save settings. Example: firewall-cmd --zone=public --add-port=3000/tcp --permanent Then reload rules: firewall-cmd --reload Solution 3: On CentOS 7 Minimal you may need to install the iptables-services package (thanks to @RichieACC for the suggestion): sudo yum install -y iptables-services And then enable the service using systemd : sudo systemctl enable iptables.service And run the initscript to save your firewall rules: sudo /usr/libexec/iptables/iptables.init save Solution 4: iptables-save > /etc/sysconfig/iptables will save the current configuration wi...