ansible-playbook

Ansible synchronize prompts passphrase even if already entered at the beginning

旧巷老猫 提交于 2019-12-03 13:56:22
问题 The synchronize module of Ansible (v1.6.5) prompts for the passphrase (Enter passphrase for key) even though I already entered it at the beginning of running the playbook. Any idea why? I run my playbook with the following options: -u myuser --ask-sudo-pass --private-key=/path/to/id_rsa Here is my synchronize task: - name: synchronize source files in src location sudo: yes synchronize: src={{local_src}} dest={{project_dirs.src}} archive=yes delete=yes rsync_opts=["--compress"] when:

Correct way to create dynamic lists in Ansible

耗尽温柔 提交于 2019-12-03 12:53:42
I'm looking for advice. I have the following code that creates a list dynamically that I can then later use in a template. This is a copy of the test code I put together - for the actual role I just added the admins|regex_replace variable into the j2 template. --- - hosts: localhost gather_facts: false vars: # define empty admins var first so ansible doesn't complain admins: admin_accounts: - name: john uid: 1000 group: sysadmin shell: /bin/bash comment: "Unix Administrator" - name: paul uid: 1001 group: sysadmin shell: /bin/bash comment: "Unix Administrator" - name: george uid: 1002 group:

How do I use remote machine's SSH keys in ansible git module

≡放荡痞女 提交于 2019-12-03 12:15:55
问题 I've been trying to get Ansible to provision a remote machine, and I want the remote machine to be set up with its own keys, and have the ability to clone git repositories from Bitbucket. The user is set up, has its own id_rsa.pub, and the key has been registered with bitbucket. But, when I use the Ansible Git module, it looks like the module always tries to use the keys from the machine running the playbook. How do I get the git module to use the id_rsa.pub from the remote machine? The

ansible ignore the run_once configuration on task

…衆ロ難τιáo~ 提交于 2019-12-03 11:03:33
I am using Ansible and I want to run a task only once. I follow the documentation about how to configure and run a task only once - name: apt update shell: apt-get update run_once: true But when I run Ansible, it always runs this task. How can I run my task only once. The run_once option will run every time your Playbook/tasks runs, but will only run it once during the specific run itself. So every time you run the play, it will run, but only on the first host in the list. If you're looking for a way to only run that command once, period, you'll need to use the creates argument. Using your

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: In a playbook, filter a role by tag(s) without passing at the command-line

半世苍凉 提交于 2019-12-03 10:27:16
问题 In Ansible 1.7, I can use --tags from the command-line to only run a subset of that playbooks tasks. But I'm wanting to bake into my playbook to run a set of roles with only tasks that match tags. That is, I don't want to have to pass this in via the command-line since it will be the same every time. At first I thought it was this command, but this does the opposite: tagging tasks with these tags instead of filtering them out based on this. roles: - { role: webserver, port: 5000, tags: [ 'web

Running a SELECT Query with an Ansible Task

帅比萌擦擦* 提交于 2019-12-03 09:50:19
In this list of mysql db modules for Ansbile, there's one for creating a db, or creating a user, etc. I would like to run a query against a pre-existing table and use the results of that query to populate an Ansible variable (list of IP addresses, and node type) upon which I would run different tasks, depending on node type. How can that be done in Ansible? This is approximately how to do it (but it is untested): - name: Retrieve stuff from mysql command: > mysql --user=alice --password=topsecret dbname --host=147.102.160.1 --batch --skip-column-names --execute="SELECT stuff from stuff_table"

Copy local file if exists, using ansible

孤街浪徒 提交于 2019-12-03 09:38:26
I'm working in a project, and we use ansible to create a deploy a cluster of servers. One of the tasks that I've to implement, is to copy a local file to the remote host, only if that file exists locally. Now I'm trying to solve this problem using this - hosts: 127.0.0.1 connection: local tasks: - name: copy local filetocopy.zip to remote if exists - shell: if [[ -f "../filetocopy.zip" ]]; then /bin/true; else /bin/false; fi; register: result - copy: src=../filetocopy.zip dest=/tmp/filetocopy.zip when: result|success Bu this is failing with the following message: ERROR: 'action' or 'local

Ansible - Define Inventory at run time

拟墨画扇 提交于 2019-12-03 08:13:56
I am liitle new to ansible so bear with me if my questions are a bit basic. Scenario: I have a few group of Remote hosts such as [EPCs] [Clients] and [Testers] I am able to configure them just the way I want them to be. Problem: I need to write a playbook, which when runs, asks the user for the inventory at run time. As an example when a playbook is run the user should be prompted in the following way: "Enter the number of EPCs you want to configure" "Enter the number of clients you want to configure" "Enter the number of testers you want to configure" What should happen: Now for instance the