Ansible Notes: Difference between revisions

From Federal Burro of Information
Jump to navigationJump to search
No edit summary
No edit summary
Line 20: Line 20:
  mkdir /etc/ansible
  mkdir /etc/ansible
  vi /etc/ansible/hosts
  vi /etc/ansible/hosts
== Cloud-init to make tags facts ==
<pre>
    - path: /etc/facter/facts.d/tags.sh
      permissions: 0755
      content: |
        #!/usr/bin/env bash
        instanceId=`curl http://169.254.169.254/latest/meta-data/instance-id 2>/dev/null`
        region=`curl http://169.254.169.254/latest/meta-data/placement/availability-zone 2>/dev/null | sed 's/[a-z]$//g'`
        /usr/bin/aws ec2 describe-tags --filters "Name=resource-id,Values=$instanceId" --region $region | jq '.Tags[] | "ec2_tag_" + .Key + "=" + .Value' | tr [:upper:] [:lower:] | tr -d '"'
        exit 0
</pre>

Revision as of 20:39, 7 February 2017

output to one line:

 cat /tmp/david/report.java  | perl -n -e " $/ = '' ; print join ( ',' , split\"\n\" ) . \"\n\"; " | more

or -o :P


Git install

under rhel6:

cd ~
mkdir work
yum install gcc python-devel
git clone https://github.com/ansible/ansible.git
git submodule update --init --recursive
make install
mkdir /etc/ansible
vi /etc/ansible/hosts

Cloud-init to make tags facts

    - path: /etc/facter/facts.d/tags.sh
      permissions: 0755
      content: |
        #!/usr/bin/env bash
        instanceId=`curl http://169.254.169.254/latest/meta-data/instance-id 2>/dev/null`
        region=`curl http://169.254.169.254/latest/meta-data/placement/availability-zone 2>/dev/null | sed 's/[a-z]$//g'`
        /usr/bin/aws ec2 describe-tags --filters "Name=resource-id,Values=$instanceId" --region $region | jq '.Tags[] | "ec2_tag_" + .Key + "=" + .Value' | tr [:upper:] [:lower:] | tr -d '"'
        exit 0