• ansible

    Get systemd services in ansible plays

    Hi, this is a tip to get details about linux (e.g. systemd) services in an ansible play. Just use the ansible service_facts module. You can use it without passing any argument. – name: Populate service facts   ansible.builtin.service_facts: You can access services by using ansible_facts.services. As this is an dictionary, a single service is addressable by using ansible_facts.services[{{ service-name }}]. – name: show all service facts   debug:     var: ansible_facts.services[{{ service_name }}] A few more examples: – name: Retrieve data about single service   debug:     var: ansible_facts.services.httpd – name: get a particular service attribute   debug:     var: ansible_facts.services.httpd.state – name: Test (RHEL7 and higher) if service is up and running   fail:     msg: “Service httpd…

  • ansible,  DevOps

    use ansible module copy instead of template for small files

    In order to adapt files and their content on target servers I am used to using ansible copy module. owever, if you only have a small file with just one or a few lines, you can do so without creating a jinja2 template. Here is the little cheat: Just use ansible’s copy module. – copy:   content: “env: {{ my_environment_var }}”   dest: /app/env.cfg That’s it. This creates a file with variable content, without need to create a template.

  • Branching & Merging,  Git

    merge particular files in another branch

    Every now and then I am faced with the question of how I can transfer individual files from a feature branch. git cherry-pick is intended for taking over the contents of a commit. But if I only want to take over individual files, this tool is probably not the solution. In order not to make it too exciting, here is the simple answer: I want to explain it using a specific example. In the feature branch 426-great-new-feature I have the files iWwantThat.yml and alsoNeeded2.py. To transfer these two files and only these to the main branch, I switch to the main branch and run the git checkout: git checkout main…