ansible-2.x

Ansible SSH error during play

穿精又带淫゛_ 提交于 2019-12-12 03:32:44
问题 I get a strange error with Ansible. First of all, the first role works fine but when Ansible tries to execute the seconde one it failed because of ssh error. Environment : OS: CentOS 7 Ansible version: 2.2.1.0 Python version: 2.7.5 OpenSSH version: OpenSSH_6.6.1p1, OpenSSL 1.0.1e-fips 11 Feb 2013 Ansible command which is executed : ansible-playbook -vvvv -i inventory/dev playbook_update_system.yml --limit "db[0]" Playbook : - name: "HUB Playbook | Updating system packages on {{ ansible

Ansible 2.2 : Restart process using variable in handlers name

送分小仙女□ 提交于 2019-12-12 03:09:17
问题 I want to do something like this : - copy: src: file{{ item }}.xml dest: target_file{{ item }}.xml notify: restart process{{ item }} with_sequence: start=1 end={{ number_of_process }} Expected result : the process 1 is restarted only if configuration file target_file1 has been modified, the process 2 is restarted only if configuration file target_file2 has been modified etc. Real result is the restart of all process when one configuration file is modified. Any idea to restart only the desired

ansible ssh to json_query response values in loop

跟風遠走 提交于 2019-12-11 16:58:22
问题 Team, I have response from json_query which is a dict key:value and i would like to iterate over all values and run ssh command for each value Below gets me list of all nodes - name: "Fetch all nodes from clusters using K8s facts" k8s_facts: kubeconfig: $WORKSPACE kind: Node verify_ssl: no register: node_list - debug: var: node_list | json_query(query) vars: query: 'resources[].{node_name: metadata.name, nodeType: metadata.labels.nodeType}' TASK [3_validations_on_ssh : debug] ok: [target1] =>

Creating instance and tagging via ansible

拟墨画扇 提交于 2019-12-11 11:58:49
问题 I am using ansible to create instance in different AZ , i am facing two issues here: I need to create 3 instances in AZ , but the below play creates 6 instances such that 3 instances in AZ-a and 3 in AZ-b I am trying to tag these instances as well, using a sequence as they are being created, but i am not able to pass/traverse the json returned. Here are the plays: --- - name: Create ES Master Node instances ec2: key_name: "{{ aws_key_name }}" instance_type: "{{ aws_instance_type }}" image: "{

Conditional role inclusion fails in Ansible

一世执手 提交于 2019-12-11 08:25:25
问题 I want to run an Ansible role conditionally, i.e. only when some binary does NOT exist (which for me implies absence of some particular app installation). Something like the pattern used here. Using the following code in my playbook: - hosts: my_host tasks: - name: check app existence command: /opt/my_app/somebinary register: myapp_exists ignore_errors: yes roles: - { role: myconditional_role, when: myapp_exists|failed } - another_role_to_be_included_either_way Here is the output: PLAY ******

How retrieve the name of specific dictionary - Ansible

对着背影说爱祢 提交于 2019-12-11 05:34:27
问题 I need help to retrieve only the name of the Virtual Machines of my ESXI Host. - name: VM-FACTS vmware_vm_facts: hostname: "{{ ansible_hostname }}" username: "{{ ansible_user }}" password: "{{ ansible_password }}" validate_certs: False delegate_to: localhost register: vmfacts - name: Debug debug: var: vmfacts.virtual_machines Output of the variable: ok: [xxxxx] => { "vmfacts.virtual_machines": { "001-MV-Test": { "cluster": null, "esxi_hostname": "xxxxx", "guest_fullname": "Red Hat Enterprise

Ansible 2 conditionals using with_items in loop

狂风中的少年 提交于 2019-12-11 04:07:32
问题 I'm trying to run a few Ansible commands depending on the outcome of a conditional check in my tasks based on the presence of a boolean and am tying myself up in knots trying to get it to work. The desired outcome is as follows, and should be run for each item in the hosts array : Check if the lynchburg variable is true or false If the lynchburg variable is true : Setup the folder structure if it doesn't already exist Create gulpfile.js from the included template file if it doesn't already

Probable quoting issue using the stdin argument of ansible's shell module

谁说我不能喝 提交于 2019-12-11 02:54:25
问题 I've got a playbook with the following tasks: - set_fact: asg_filter: > .AutoScalingGroups[] | select(.Tags[] | select(.Key == "Role").Value == "myrole") - shell: aws autoscaling --region us-west-2 describe-auto-scaling-groups | jq --compact-output "{{ asg_filter }}" register: asgs_result - set_fact: stale_instance_filter: > .LaunchConfigurationName as $lc | .Instances[] | select(.LaunchConfigurationName != $lc) | .InstanceId Now I want to use stale_instance_filter on asgs_result.stdout . The

How to add multiple inventory files in command line while executing a playbook

孤者浪人 提交于 2019-12-11 00:21:46
问题 I am having a playbook with two different plays Sample.yml - name : Play1 hosts: Host1 tasks: ... - name: Play2 hosts: Host2 tasks: ... I need to run this playbook with two different hosts( Host1 and Host2 ) and these two different hosts are present in two separate files( Hostfile1 and Hostfile2 ) under inventory/ directory. inventory/ Hostfile1 Hostfile2 . . HostfileN I want to know how to include two different hosts file while running the playbook. I know by including the entire folder (

Access ansible.cfg variable in task

邮差的信 提交于 2019-12-10 21:23:33
问题 How can I refer remote_tmp (or any other) value defined in ansible.cfg in my tasks? For example, in the my_task/defaults/main.yml : file_ver: "1.5" deb_file: "{{ defaults.remote_tmp }}/deb_file_{{ file_ver }}.deb" produces an error: fatal: [x.x.x.x]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: {{ defaults.remote_tmp }}/deb_file_{{ file_ver }}.deb: 'defaults' is undefined\... } 回答1: You can't