ansible-playbook

Running a task on a single host always with Ansible?

◇◆丶佛笑我妖孽 提交于 2020-01-03 03:12:07
问题 I am writing a task to download a database dump from a specific location. It will always be run on the same host. So I am including the task as follows in the main playbook: tasks: include: tasks/dl-db.yml The content of the task is: --- - name: Fetch the Database fetch: src=/home/ubuntu/mydb.sql.gz dest=/tmp/mydb.sql.bz fail_on_missing=yes But I want it to fetch from a single specific host not all hosts. Is a task the right approach for this? 回答1: If all you need to happen is that it's only

Ansible, Juniper CLI commands. Timeout Error?

守給你的承諾、 提交于 2020-01-02 09:52:28
问题 I am trying to transfer an automation script I made in Python, to ansible (company request), and I have NEVER worked with ansible before. I have tried the "wait_for:", but I have not gotten that to work either. In the script, I could set dev.timeout=None or whatever I needed. I am finding it hard to figure out where I can do this in ansible. I have tried setting the timeout in the "ansible.cfg" file. But that doesnt work. I can do simple commands, like: cli="show version", or cli="show system

Ansible - with_dict: dictionary - How to use variables defined in each dictionary which depends upon others

风格不统一 提交于 2020-01-02 04:05:36
问题 Environment is: Ansible 1.9.2, CentOS 6.5 I have created a role to download JAVA (.tar.gz) artifact files for 3 different JAVA versions from Artifactory. I'm trying to use Ansible's with_dict feature (instead of using with_items). Created the following files: $ cat roles/java/defaults/main.yml --- java_versions: java7_60: version: 1.7.60 group_path: com/oracle/jdk classifier: linux-x64 ext: tar.gz dist_file: "jdk-{{ version }}-{{ classifier }}-{{ ext }}" # dist_file: "jdk-{{item.value.version

ansible: Is there something like with_fileglobs for files on remote machine?

混江龙づ霸主 提交于 2020-01-02 00:13:15
问题 I'm trying to turn these lines into something I can put in an ansible playbook: # Install Prezto files shopt -s extglob shopt -s nullglob files=( "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/!(README.md) ) for rcfile in "${files[@]}"; do [[ -f $rcfile ]] && ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile##*/}" done So far I've got the following: - name: Link Prezto files file: src={{ item }} dest=~ state=link with_fileglob: - ~/.zprezto/runcoms/z* I know it isn't the same, but it would select the same

Ansible cannot make dir /$HOME/.ansible/cp

岁酱吖の 提交于 2020-01-01 15:37:48
问题 I'm getting a very strange error when I run ansible: GATHERING FACTS *************************************************************** fatal: [i-0f55b6a4] => Could not make dir /$HOME/.ansible/cp: [Errno 13] Permission denied: '/$HOME' TASK: [Task #1] *************************************************************** FATAL: no hosts matched or all hosts have already failed -- aborting PLAY RECAP ******************************************************************** to retry, use: --limit @/home

Using hyphen in ansible

三世轮回 提交于 2020-01-01 09:26:07
问题 I am learning Ansible but I am getting confused when to use hyphen and when not to use hyphen in playbook. As I know, hyphen is used for list in Ansible. For example, --- # my first playbook - hosts: webservers ( why did we use hyphen here it is not a list) tasks: - name: installing httpd yum: name=httpd state=installed ( why we shouldn't use hyphen here). From Ansible documentation, it is said that hyphen is for list, for example: fruits: - apple - grapes - orange So, I am confused when to

Ansible lineinfile insertafter injects line at end of file

房东的猫 提交于 2020-01-01 09:21:48
问题 I'm using lineinfile as follows: lineinfile dest=./hosts_exp insertafter='\[hosts1\]' line="xxxxxxxxx" state=present My hosts_exp is as follows: [local] localhost [hosts1] [hosts2] [hosts3] lineinfile inserts the text after [hosts3] instead of inserting it after [hosts1]. 回答1: use: lineinfile: dest: "./hosts_exp" line: "xxxxxxxxx" insertafter: '^\[hosts1\]' state: present 回答2: example: - name: "blah" lineinfile: dest: "/test.sh" insertafter: 'test text' line: "text add" state: present 回答3: It

Running an Ansible Playbook using Python API 2.0.0.1

女生的网名这么多〃 提交于 2020-01-01 06:10:27
问题 Ansible version : 2.0.0.1 I've been looking around quite a bit now, and most documentation I find is either incomplete or deprecated (this post is for version 1.8.4, ie) I'm trying to launch an Ansible playbook through the Python API. Ansible's documentation seem to be showing how to generate and play tasks, but not how to load and run a playbook yml file. I've been digging into the code to try to understand how to launch it, and I think I've done some progress, but I'm really hitting a wall.

How to traverse a nested dict structure with Ansible?

人走茶凉 提交于 2020-01-01 05:38:28
问题 I have the following dict structure variable in an ansible playbook: apache_vhosts: - name: foo server_name: foo.com server_aliases: - a.foo.com - b.foo.com - c.foo.com - name: bar server_name: bar.com server_aliases: - d.bar.com - e.bar.com - f.bar.com I need to create a symlink for each of the server_name and server_aliases domains, e.g.: /tmp/foo.com -> /var/www/foo /tmp/a.foo.com -> /var/www/foo /tmp/b.foo.com -> /var/www/foo /tmp/c.foo.com -> /var/www/foo /tmp/bar.com -> /var/www/bar

Correct way to create dynamic lists in Ansible

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-01 04:52:06
问题 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: