ansible
What is the difference between a Docker Container and an Ansible Playbook?
There are many reasons most articles talk about using them together. Think of Ansible as a way of installing and configuring a machine where you can go back and tweak any individual step of that install and configuration in the future. You can then scale that concept out to many machines as you are able … Read more
What do double curly braces ({{) mean in YAML files (as used by Ansible)?
I found this YAML syntax overview in Ansible documantation, to be fairly useful. It says that double curly braces {{ variable }} are used to evaluate expressions. Whilst distinguishing a single curly braces (after a colon), that is used to declare a dictionary. For example: satchmo: {name: Louis Armstrong, music: Jazz, instrument: Trumpet} Also, take … Read more
How do ansible host_vars work?
Since the documentation is not very specific on this topic here is the order of precedence for vars in the current version of Ansible (the first item has the highest precedence): Vars set on the command line -e foo=set_on_cmd_line Vars set in the vars_files: block in the play Vars set in the vars: block in … Read more
How to compare kernel (or other) version numbers in Ansible
There is a test for it: {{ ansible_distribution_version is version(‘12.04’, ‘>=’) }} {{ sample_version_var is version(‘1.0’, operator=”lt”, strict=True) }}
Ansible non-root sudo user and “become” privilege escalation
Why am I getting permission denied? Because APT requires root permissions (see the error: are you root?) and you are running the tasks as david. Per these settings: become: true become_user: david become_method: sudo Ansible becomes david using sudo method. It basically runs its Python script with sudo david in front. the user ‘david’ on … Read more
Add a new key-value to a json file using Ansible
since the file is of json format, you could import the file to a variable, append the extra key:value pairs you want, and then write back to the filesystem. here is a way to do it: — – hosts: localhost connection: local gather_facts: false vars: tasks: – name: load var from file include_vars: file: /tmp/var.json … Read more
ansible wget then exec scripts => get_url equivalent
This worked for me: – name: Download zsh installer get_url: url: https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh dest=/tmp/zsh-installer.sh – name: Execute the zsh-installer.sh shell: /tmp/zsh-installer.sh – name: Remove the zsh-installer.sh file: path: /tmp/zsh-installer.sh state: absent
Ansible failed to transfer file to /command
do you have sftp subsystem enabled in sshd on the remote server? You can check it in /etc/sshd/sshd_config, the config file name depends on your distribution…anyway, look there for: Subsystem sftp /usr/lib/ssh/sftp-server If this line is commented-out, the sftp is disabled. To fix it, you can either enable sftp, or change Ansible configuration. I prefer … Read more
Ansible – print gathered facts for debugging purposes [duplicate]
Use setup module as ad-hoc command: ansible myhost -m setup