ansible-playbook

Run Command Inside of Docker Container Using Ansible

旧时模样 提交于 2019-11-28 15:59:54
问题 what I'm trying to accomplish is to run commands inside of a Docker container that has already been created on a Digital Ocean Ubuntu/Docker Droplet using Ansible. Can't seem to find anything on this, or I'm majorly missing something. This is my Ansible task in my play book. I'm very new to Ansible so any advice or wisdom would be greatly appreciated. - name: Test Deploy hosts: [my-cluster-of-servers] tasks: - name: Go Into Docker Container And Run Multiple Commands docker: name: [container

How can I test jinja2 templates in ansible?

一世执手 提交于 2019-11-28 15:37:13
问题 Sometimes I need to test some jinja2 templates that I use in my ansible roles. What is the simplest way for doing this? For example, I have a template (test.j2): {% if users is defined and users %} {% for user in users %}{{ user }} {% endfor %} {% endif %} and vars (in group_vars/all): --- users: - Mike - Smith - Klara - Alex 回答1: At this time exists 4 different variants: 1_Online (using https://cryptic-cliffs-32040.herokuapp.com/) Based on jinja2-live-parser code. 2_Interactive (using python

How can escape colon in a string within an Ansible YAML file?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 08:07:14
I want to change one line of my code in file /var/www/kibana/config.js during installation from elasticsearch: "http://"+window.location.hostname+":9200" to elasticsearch: "http://192.168.1.200:9200" Here I tried to use lineinfile to do that as show below - name: Comment out elasticsearch the config.js to ElasticSearch server lineinfile: dest=/var/www/kibana/config.js backrefs=true regexp="(elasticsearch.* \"http.*)$" line="elasticsearch\: \" {{ elasticsearch_URL }}:{{ elasticsearch_port }} \" " state=present I have set variables of {{elasticsearch_URL}} and {{elasticsearch_port}} to http:/

How to use 'skip: true' with 'with_first_found'?

冷暖自知 提交于 2019-11-28 06:03:27
问题 I would like to use the following task in a playbook: - include: "{{ prerequisites_file }}" with_first_found: - "prerequisites-{{ ansible_distribution }}.yml" - "prerequisites-{{ ansible_os_family }}.yml" loop_control: loop_var: prerequisites_file I would like it to just pass if no files matching the architecture were found. When run as is, in such a case, it produces an error: TASK [ansible-playbook : include] *************************************** fatal: [ansible-playbook]: FAILED! => {

Ansible wait_for module, start at end of file

瘦欲@ 提交于 2019-11-28 05:38:40
问题 With the wait_for module in Ansible if I use search_regex='foo' on a file it seems to start at the beginning of the file, which means it will match on old data, thus when restarting a process/app (Java) which appends to a file rather than start a new file, the wait_for module will exit true for old data, but I would like to check from the tail of the file. 回答1: Regular expression in search_regex of wait_for module is by default set to multiline. You can register the contents of the last line

Ansible: overriding dictionary variables in extra-vars [duplicate]

Deadly 提交于 2019-11-28 04:51:16
问题 This question already has an answer here: Ansible. override single dictionary key [duplicate] 4 answers In my Ansible playbook I have a nested variable declaration as shown below in a variable file. repo: branch: int url: git@github:user/repo.git dest: "/var/code" How would I override the branch param in extra-vars? I tried something like this below but it didn't work. --extra-vars "repo.branch=exec_refactor" neither this --extra-vars "repo[branch]=exec_refactor" using JSON representation

How to run a task when variable is undefined in ansible?

女生的网名这么多〃 提交于 2019-11-28 04:48:09
I am looking for a way to perform a task when ansible variable is not registers /undefined e.g -- name: some task command: sed -n '5p' "{{app.dirs.includes}}/BUILD.info" | awk '{print $2}' when: (! deployed_revision) AND ( !deployed_revision.stdout ) register: deployed_revision From the ansible docs : If a required variable has not been set, you can skip or fail using Jinja2’s defined test. For example: tasks: - shell: echo "I've got '{{ foo }}' and am not afraid to use it!" when: foo is defined - fail: msg="Bailing out. this play requires 'bar'" when: bar is not defined So in your case, when:

How to wait for server restart using Ansible?

梦想与她 提交于 2019-11-28 03:23:28
I'm trying to restart the server and then wait, using this: - name: Restart server shell: reboot - name: Wait for server to restart wait_for: port=22 delay=1 timeout=300 But I get this error: TASK: [iptables | Wait for server to restart] ********************************* fatal: [example.com] => failed to transfer file to /root/.ansible/tmp/ansible-tmp-1401138291.69-222045017562709/wait_for: sftp> put /tmp/tmpApPR8k /root/.ansible/tmp/ansible-tmp-1401138291.69-222045017562709/wait_for Connected to example.com. Connection closed You should change the wait_for task to run as local_action , and

Ansible: Access host/group vars from within custom module

半腔热情 提交于 2019-11-28 03:14:37
问题 Is there a way how one can access host/group vars from within a custom written module? I would like to avoid to pass all required vars as module parameters. My module is written in Python and I use the boilerplate. I checked pretty much all available vars but they are not stored anywhere: def main(): pprint(dir()) pprint(globals()) pprint(locals()) for name in vars().keys(): print(name) Now my only hope is they are somehow accessible through the undocumented module utils. I guess it is not

How to automatically install Ansible Galaxy roles?

元气小坏坏 提交于 2019-11-28 02:48:48
All my Ansible playbooks/roles are checked in to my git repo. However, for Ansible Galaxy roles I always have to explicitly download them one by one on every machine I want to run Ansible from. It's even tough to know in advance exactly which Ansible Galaxy roles are needed until Ansible complains about a missing role at runtime. How is one supposed to manage the Ansible Galaxy role dependencies? I would like to either have them checked into my git repo along with the rest of my ansible code or have them automatically be identified and downloaded when I run Ansible on a new machine. You should