ansible-2.x

Execute curl -X with ansible playbook

為{幸葍}努か 提交于 2019-12-03 11:01:39
问题 I want to execute the next command using ansible playbook: curl -X POST -d@mesos-consul.json -H "Content-Type: application/json" http://marathon.service.consul:8080/v2/apps How can I run it? If I run: - name: post to consul uri: url: http://marathon.service.consul:8080/v2/apps/ method: POST body: "{{ lookup('file','mesos-consul.json') }}" body_format: json HEADER_Content-Type: "application/json" I have the next fail: fatal: [172.16.8.231]: FAILED! => {"failed": true, "msg": "ERROR! the file

iteration using with_items and register

折月煮酒 提交于 2019-12-03 10:49:40
Looking for help with a problem I've been struggling with for a few hours. I want to iterate over a list, run a command, register the output for each command and then iterate with debug over each unique registers {{ someregister }}.stdout For example, the following code will spit out "msg": "1" and "msg": "2" --- - hosts: localhost gather_facts: false vars: numbers: - name: "first" int: "1" - name: "second" int: "2" tasks: - name: Register output command: "/bin/echo {{ item.int }}" register: result with_items: "{{ numbers }}" - debug: msg={{ item.stdout }} with_items: "{{ result.results }}" If

Ansible template adds 'u' to array in template

两盒软妹~` 提交于 2019-12-03 06:20:23
I have the following vars inside of my ansible playbook I got the following structure domains: - { main: 'local1.com', sans: ['test.local1.com', 'test2.local.com'] } - { main: 'local3.com' } - { main: 'local4.com' } And have the following inside of the my conf.j2 {% for domain in domains %} [[acme.domains]] {% for key, value in domain.iteritems() %} {% if value is string %} {{ key }} = "{{ value }}" {% else %} {{ key }} = {{ value }} {% endif %} {% endfor %} {% endfor %} Now when I go in the VM and see the file I get the following: Output [[acme.domains]] main = "local1.com sans = [u'test

How can I show progress for a long-running Ansible task?

别来无恙 提交于 2019-12-03 03:32:37
问题 I have a some Ansible tasks that perform unfortunately long operations - things like running an synchronization operation with an S3 folder. It's not always clear if they're progressing, or just stuck (or the ssh connection has died), so it would be nice to have some sort of progress output displayed. If the command's stdout/stderr was directly displayed, I'd see that, but Ansible captures the output. Piping output back is a difficult problem for Ansible to solve in its current form. But are

How do I pass username and password while using Ansible Git module?

[亡魂溺海] 提交于 2019-12-03 03:10:03
问题 While doing clone, push or pull of a private git repository hosted internally (e.g. on a GitLab instance) with Ansible's Git module, how do I specify username and password to authenticate with the Git server? I don't see any way to do this in the documentation. 回答1: You can use something like this: --- - hosts: all gather_facts: no become: yes tasks: - name: install git package apt: name: git - name: Get updated files from git repository git: repo: "https://{{ githubuser | urlencode }}:{{

Additional conditions for tasks inside a block

半城伤御伤魂 提交于 2019-12-02 17:57:00
问题 I'm trying to enclose tasks in the block with some when condition. Also some tasks inside this block have additional conditions. The problem is such tasks (with additional conditions) are skipped. Both block's condition and all additional conditions are true. Below there is a sample play: - block: - set_fact: packages_to_install: "{{ packages_to_install }} + [ '{{ (distrs.stdout | from_json).postgresql }}' ]" - set_fact: packages_to_install: "{{ packages_to_install }} + [ '{{ (distrs.stdout |

ansible register with loop debug print not working

浪子不回头ぞ 提交于 2019-12-02 17:28:36
问题 i have a simple playbook that is supposed to display my services status. and i want to view the output from the machine to see if the status is active or not. so i used a debug print, like so: - name: name_of_services shell: systemctl status {{item}} with_items: - service1 - service2 register: out - debug: var=item.stdout_lines with_items: out.results when i execute this i get a lot of info i don't want plus the item.stdout_lines info that i do want in the end of it. how is it possible to

How can I show progress for a long-running Ansible task?

*爱你&永不变心* 提交于 2019-12-02 17:03:47
I have a some Ansible tasks that perform unfortunately long operations - things like running an synchronization operation with an S3 folder. It's not always clear if they're progressing, or just stuck (or the ssh connection has died), so it would be nice to have some sort of progress output displayed. If the command's stdout/stderr was directly displayed, I'd see that, but Ansible captures the output. Piping output back is a difficult problem for Ansible to solve in its current form . But are there any Ansible tricks I can use to provide some sort of indication that things are still moving?

Difference between become and become_user in Ansible

北城以北 提交于 2019-12-02 15:29:25
Recently I started digging into Ansible and writing my own playbooks. However, I have a troubles with understanding difference between become and become_user . As I understand it become_user is something similar to su <username> , and become means something like sudo su or "perform all commands as a sudo user". But sometimes these two directives are mixed. Could you explain the correct meaning of them? become_user defines the user which is being used for privilege escalation . become simply is a flag to either activate or deactivate the same. Here are three examples which should make it clear:

ansible register with loop debug print not working

别等时光非礼了梦想. 提交于 2019-12-02 12:33:53
i have a simple playbook that is supposed to display my services status. and i want to view the output from the machine to see if the status is active or not. so i used a debug print, like so: - name: name_of_services shell: systemctl status {{item}} with_items: - service1 - service2 register: out - debug: var=item.stdout_lines with_items: out.results when i execute this i get a lot of info i don't want plus the item.stdout_lines info that i do want in the end of it. how is it possible to view the output of my command better? For modules, including debug, called in a loop (ie with_items), the