ansible-playbook

Creating CloudWatch Alarm metrics using ansible

笑着哭i 提交于 2019-12-12 03:38:24
问题 I have a inventory file which looks like : [database] syd01-dev-shared.ce4l5of4bl3z.ap-southeast-2.rds.amazonaws.com I need to configure 3 cloudwatch metrics for the above RDS endpoint, by reading the inventory. The DBInstanceIdentifier is actually syd01-dev-shared only, how can i actually pick this part and feed it to something like below?? - name: Create CPU utilization metric alarm sudo: false local_action: ec2_metric_alarm state=present region={{region}} name="HOW_TO_READ

Ansible recursive checks in playbooks

二次信任 提交于 2019-12-12 03:37:32
问题 We need to go through this structure Zone spec https://gist.github.com/git001/9230f041aaa34d22ec82eb17d444550c I was able to run the following snipplet but now I'm stucked at the error checking. playbook -- - hosts: all gather_facts: no vars_files: - "../doc/application-zone-spec.yml" roles: - { role: ingress_add, customers: "{{ application_zone_spec }}" } role - name: check if router exists shell: "oc get dc -n default {{ customers.zone_name }}-{{ item.type }}" with_items: "{{ customers

How to remove 'all other' files for copy/template modules in ansible?

旧时模样 提交于 2019-12-12 03:22:40
问题 Small task: - name: Configure hosts template: src=host.cfg.j2 dest=/etc/shinken/hosts/{{item.host_name}}.cfg with_items: shinken_hosts when: shinken_hosts is defined notify: reload config I want to remove all other configs (files) in /etc/shinken/hosts/ configured by this task. How can I do this? (It is really important if I fix a typo in 'shinken_hosts', and want to automatically remove old config with mistake in the name). 回答1: you might want to check this, slide 19. This assumes that you

Ansible fileinline not working with loop

倾然丶 夕夏残阳落幕 提交于 2019-12-12 02:42:40
问题 I am trying to add or edit multiple lines in a file using lineinfile but not working. I am using below code with no luck Ref: ansible: lineinfile for several lines? # vim /etc/ansible/playbook/test-play.yml - hosts: tst.wizvision.com tasks: - name: change of line lineinfile: dest: /root/test.txt regexp: "{{ item.regexp }}" line: "{{ item.line }}" backrefs: yes with_items: - { regexp: '^# line one', line: 'NEW LINE ONE' } - { regexp: '^# line two', line: 'NEW LINE TWO' } Ansible Error: #

loops over the registered variable to inspect the results in ansible

青春壹個敷衍的年華 提交于 2019-12-11 19:29:21
问题 I have an ansible-playbook that creates the multiple ec2 security groups using with_items and register the result. here is the var file for this playbook: --- ec2_security_groups: - sg_name: nat_sg sg_description: This sg is for nat instance sg_rules: - proto: tcp from_port: 22 to_port: 22 cidr_ip: 0.0.0.0/0 - sg_name: web_sg sg_description: This sg is for web instance sg_rules: - proto: tcp from_port: 22 to_port: 22 cidr_ip: 0.0.0.0/0 - proto: tcp from_port: 80 to_port: 80 cidr_ip: 0.0.0.0/0

save file in local machine which was generate in remote machine?

筅森魡賤 提交于 2019-12-11 13:36:50
问题 test.yml --- - hosts: webservers remote_user: username tasks: - name: Execute the script command: sh /home/username/top.sh top.sh #!/bin/bash top > system.txt I run test.yml in local machine, it will run the shell script in remote machine and save the command in system.txt file. location of top.sh : remote, location of system.txt : remote But I am looking for location of top.sh : local (but I need to run this command in remote), location of system.txt : local How to achieve this? 回答1: You can

Ansible “when variable == true” not behaving as expected

血红的双手。 提交于 2019-12-11 11:06:24
问题 I have the following tasks in a playbook I'm writing (results listed next to the debug statement in <>): - debug: var=nrpe_installed.stat.exists <true> - debug: var=force_install <true> - debug: var=plugins_installed.stat.exists <true> - name: Run the prep include: prep.yml when: (nrpe_installed.stat.exists == false or plugins_installed.stat.exists == true or force_install == true) tags: ['prep'] - debug: var=nrpe_installed.stat.exists <true> - debug: var=force_install <true> - debug: var

How to iterate through N level children of hosts using Ansible Playbook?

◇◆丶佛笑我妖孽 提交于 2019-12-11 10:56:05
问题 I know how to achieve this using host_vars but the problem with it is the host files can get convoluted so I'm leaning towards ini files where I can put all the data in one file. This SO post helped me have an idea how to put a collection in a variable for a particular host. I have this sample inventory: ;hosts.yml [web1] example1.com databases=["example1_com","mysql"] example2.com databases=["example1_com","mysql"] [web1:vars] ansible_host=10.0.16.21 [web2] example3.com databases=["example3

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 ******

Ansible Dict and Tags

北城以北 提交于 2019-12-11 06:14:53
问题 I have a playbook creating EC2 by using a dictionary declared in vars: then registering the IPs into a group to be used later on. The dict looks like this: servers: serv1: name: tag1 type: t2.small region: us-west-1 image: ami-**** serv2: name: tag2 type: t2.medium region: us-east-1 image: ami-**** serv3: [...] I would like to apply tags to this playbook in the simplest way so I can create just some of them using tags. For example, running the playbook with --tags tag1,tag3 would only start