How to set environmental variables using Ansible

Yes, there is a cleaner way. You can set environment variables per task: tasks: – shell: echo JAVA_HOME is $JAVA_HOME environment: JAVA_HOME: /usr/java/jre1.8.0_51 register: shellout – debug: var=shellout Output: TASK: [shell echo JAVA_HOME is $JAVA_HOME] ********************************** changed: [localhost] TASK: [debug var=shellout] **************************************************** ok: [localhost] => { “var”: { “shellout”: { “changed”: true, “cmd”: “echo JAVA_HOME … Read more

Ansible include task only if file exists

The with_first_found conditional can accomplish this without a stat or local_action. This conditional will go through a list of local files and execute the task with item set to the path of the first file that exists. Including skip: true on the with_first_found options will prevent it from failing if the file does not exist. … Read more

ansible run command on remote host in background

Simplified answer from link I mentioned in the comment: — – hosts: centos-target gather_facts: no tasks: – shell: “(cd /; python -mSimpleHTTPServer >/dev/null 2>&1 &)” async: 10 poll: 0 Note subshell parentheses. Update: actually, you should be fine without async, just don’t forget to redirect stdout: – name: start simple http server in background shell: … Read more

Installing multiple packages in Ansible

To my surprise I didn’t find the simplest solution in all the answers, so here it is. Referring to the question title Installing multiple packages in Ansible this is (using the yum module): – name: Install MongoDB yum: name: – mongodb-org-server – mongodb-org-mongos – mongodb-org-shell – mongodb-org-tools state: latest update_cache: true Or with the apt … Read more

Is there any option to list groups in Ansible?

You can simply inspect the groups variable using the debug module: ansible localhost -m debug -a ‘var=groups.keys()’ The above is using groups.keys() to get just the list of groups. You could drop the .keys() part to see group membership as well: ansible localhost -m debug -a ‘var=groups’

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)