Is there a way to make change in file but only if file exist ?
For the moment the task stop with errors.
Example : the following task
- name: “Paramétrages de suhosin pour php”
lineinfile:
dest=/etc/php5/apache2/conf.d/suhosin.ini
backup=yes
state=present
regexp=^{{ item.key }}
line=“{{ item.key }} {{ item.value }}”
insertafter=EOF
with_items:- { key: ‘suhosin.post.max_vars’, value: ‘5000’ }
- { key: ‘suhosin.request.max_vars’, value: ‘5000’ }
- { key: ‘suhosin.perdir’, value: ‘pr’ }
notify:- restart apache
will fail if /etc/php5/apache2/conf.d/suhosin.ini don’t exist ie if php5-suhosin package is not installed
failed: [127.0.0.1] => (item={‘value’: ‘5000’, ‘key’: ‘suhosin.post.max_vars’}) => {“failed”: true, “item”: {“key”: “suhosin.post.max_vars”, “value”: “5000”}, “rc”: 257}
msg: Destination /etc/php5/apache2/conf.d/suhosin.ini does not exist !
failed: [127.0.0.1] => (item={‘value’: ‘5000’, ‘key’: ‘suhosin.request.max_vars’}) => {“failed”: true, “item”: {“key”: “suhosin.request.max_vars”, “value”: “5000”}, “rc”: 257}
msg: Destination /etc/php5/apache2/conf.d/suhosin.ini does not exist !
failed: [127.0.0.1] => (item={‘value’: ‘pr’, ‘key’: ‘suhosin.perdir’}) => {“failed”: true, “item”: {“key”: “suhosin.perdir”, “value”: “pr”}, “rc”: 257}
msg: Destination /etc/php5/apache2/conf.d/suhosin.ini does not exist !
I’me about to use a pretask like this :
- name: See if suhosin file exist
shell: “[ -f ~/.oh-my-zsh ] && echo ‘Found’ || echo ‘’”
register: suhosin_installed
Is there an another way ?