Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 16090

A better way of create a file if it doesn't exist using Ansible?

$
0
0

I'd like to create an ansible task. The playbook itself should install and configure some settings in my new linux environment, so, one of the thinks I need to do is to install zsh, and after that, write one line to /etc/zsh/zshenv this way:

- name: Check if /etc/zsh/zshenv exists  ansible.builtin.stat:    path: "/etc/zsh/zshenv"  register: file_status- name: Creates /etc/zsh/zshenv if it doesn't exists  ansible.builtin.file:    path: /etc/zsh/zshenv    state: touch    owner: root    group: root    mode: '0644'  when: not file_status.stat.exists- name: configure ZDOTDIR en /etc/zsh/zshenv  ansible.builtin.lineinfile:    path: /etc/zsh/zshenv    line: 'ZDOTDIR=$HOME/.config/zsh/'    state: present

I'd like to know if ther's any way to use just one or two tasks instead of three. Even better, as I have no experience running ansible, I'd like to know if there's a better way of doing this.

Thanks a lot in advance!!


Viewing all articles
Browse latest Browse all 16090

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>