--- - name: install the postgresql packages apt: pkg={{ item }} state={{ psql_pkg_state }} with_items: '{{ postgresql_pkgs }}' notify: Restart postgresql tags: [ 'postgresql', 'postgres' ] - name: Install the packages that ansible needs to manage the postgresql users and databases apt: pkg={{ item }} state={{ psql_pkg_state }} with_items: - python-psycopg2 tags: [ 'postgresql', 'postgres' ] - name: Ensure that the postgresql server is started service: name=postgresql state=started enabled=yes when: postgresql_enabled tags: [ 'postgresql', 'postgres' ] - name: Ensure that the postgresql server is stopped and disabled service: name=postgresql state=stopped enabled=no when: not postgresql_enabled tags: [ 'postgresql', 'postgres' ]