cypher
This commit is contained in:
parent
7746597ae3
commit
4189f8dcf7
@ -17,25 +17,37 @@ Inventory = Listen von Ziel-Hosts, auf die Ansible zugreifen soll, mit Gruppen.
|
||||
Bei Aufruf von Roles in Playbooks können Tags hinzugefügt werden, sodass später nur einzelne roles ausgeführt werden können, anstatt alle.
|
||||
|
||||
Aufruf eines .yml Playbooks:
|
||||
```ansible-playbook -i [inventory] filename.yml```
|
||||
|
||||
```
|
||||
¨ansible-playbook -i [inventory] filename.yml
|
||||
```
|
||||
|
||||
## Testumgebung Lokal
|
||||
|
||||
- target-server (vagrant ubuntu) starten (nicht über virtualtoolbox starten!)
|
||||
* cmd: ''cd c:\entwicklung\ansible-test-host\''
|
||||
* cmd: ''vagrant up''
|
||||
* um von cmd in die shell zu wechseln (ist aber nicht nötig, ausser man will resultate von ansible befehlen anschauen gehen): cmd: ''vagrant ssh''
|
||||
- Windows Ubuntu App starten
|
||||
* weil key auf host geändert hat, muss neuer key angepasst werden. \\ ''ssh-keygen -f "/home/roru/.ssh/known_hosts" -R "[127.0.0.1]:2222"''
|
||||
* ''ssh 127.0.0.1 -p2222''
|
||||
* check ob target erreichbar: ''ansible -i "127.0.0.1," -e "ansible_port=2222 ansible_user=vagrant" -m ping all''
|
||||
- cmd: `cd c:\entwicklung\ansible-test-host: `
|
||||
- cmd: `vagrant up`
|
||||
- um von cmd in die shell zu wechseln (ist aber nicht nötig, ausser man will resultate von ansible befehlen anschauen gehen): cmd: `vagrant ssh`
|
||||
- WSL starten
|
||||
- weil key auf host geändert hat, muss neuer key angepasst werden. `ssh-keygen -f "/home/roru/.ssh/known_hosts" -R "[127.0.0.1]:2222"`
|
||||
- `ssh 127.0.0.1 -p2222`
|
||||
- check ob target erreichbar: `ansible -i "127.0.0.1," -e "ansible_port=2222 ansible_user=vagrant" -m ping all`
|
||||
|
||||
|
||||
## Playbook ausführen
|
||||
```ansible-playbook -i "127.0.0.1," -e "ansible_port=2222 ansible_user=vagrant" webserver.yml```
|
||||
|
||||
```
|
||||
ansible-playbook -i "127.0.0.1," -e "ansible_port=2222 ansible_user=vagrant" webserver.yml
|
||||
```
|
||||
|
||||
oder, wenn eintrag in `/etc/ansible/hosts`:
|
||||
```ansible-playbook webserver.yml```
|
||||
|
||||
```
|
||||
ansible-playbook webserver.yml
|
||||
```
|
||||
|
||||
eintrag wäre z.B.:
|
||||
|
||||
```
|
||||
[testumgenbung]
|
||||
local ansible_host=127.0.0.1 ansible_port=2222 ansible_user=vagrant
|
||||
@ -44,6 +56,7 @@ local ansible_host=127.0.0.1 ansible_port=2222 ansible_user=vagrant
|
||||
mit `--check --diff` am schluss wird Ausführung nur simuliert.
|
||||
|
||||
## Beispiel Playbook (mit Endung `.yml`)
|
||||
|
||||
```
|
||||
---
|
||||
- hosts: local
|
||||
|
||||
113
cypher/README.md
113
cypher/README.md
@ -40,42 +40,59 @@ ON CREATE SET n.nicknames=["J"];
|
||||
|
||||
Kombiniert:
|
||||
|
||||
```MERGE (n :Student {name:"Jack",age:22})
|
||||
```
|
||||
MERGE (n :Student {name:"Jack",age:22})
|
||||
ON CREATE SET n.nicknames=["Jacko"]
|
||||
ON MATCH SET n.nicknames=["Jackie"];```
|
||||
ON MATCH SET n.nicknames=["Jackie"];
|
||||
```
|
||||
|
||||
#### Select
|
||||
|
||||
Match all nodes with label "Student", show name and first of the nickname(s)
|
||||
|
||||
```MATCH (n :Student) RETURN n.name, n.nicknames[0];```
|
||||
```MATCH (rog :Student {name: "Roger"}), (tim :Student {name: "Timothy"}) RETURN rog, tim```
|
||||
```
|
||||
MATCH (n :Student) RETURN n.name, n.nicknames[0];
|
||||
```
|
||||
|
||||
```
|
||||
MATCH (rog :Student {name: "Roger"}), (tim :Student {name: "Timothy"}) RETURN rog, tim
|
||||
```
|
||||
|
||||
##### Where clause
|
||||
|
||||
Match all nodes with label "Student" and name "Tim"
|
||||
|
||||
```MATCH (n :Student { name:"Roger" } ) RETURN n;
|
||||
```
|
||||
MATCH (n :Student { name:"Roger" } ) RETURN n;
|
||||
is the same as:
|
||||
MATCH (n :Student ) WHERE n.name="Roger" RETURN n;```
|
||||
MATCH (n :Student ) WHERE n.name="Roger" RETURN n;
|
||||
```
|
||||
|
||||
###### AND
|
||||
|
||||
```MATCH (n :Student ) WHERE n.name="Roger" AND n.age=42 RETURN n;```
|
||||
```
|
||||
MATCH (n :Student ) WHERE n.name="Roger" AND n.age=42 RETURN n;
|
||||
```
|
||||
|
||||
###### OR
|
||||
|
||||
```MATCH (n :Student ) WHERE n.name="Roger" OR n.age=21 RETURN n;```
|
||||
```
|
||||
MATCH (n :Student ) WHERE n.name="Roger" OR n.age=21 RETURN n;
|
||||
```
|
||||
|
||||
###### NOT
|
||||
|
||||
```MATCH (n) WHERE n.name<>"Roger" AND n.name<>"Josh" RETURN n;
|
||||
```
|
||||
MATCH (n) WHERE n.name<>"Roger" AND n.name<>"Josh" RETURN n;
|
||||
oder
|
||||
MATCH (n) WHERE NOT n.name="Roger" AND NOT n.name="Josh" RETURN n;```
|
||||
MATCH (n) WHERE NOT n.name="Roger" AND NOT n.name="Josh" RETURN n;
|
||||
```
|
||||
|
||||
###### Smaller/Larger
|
||||
|
||||
```MATCH (n) WHERE n.age>=21 RETURN n;```
|
||||
```
|
||||
MATCH (n) WHERE n.age>=21 RETURN n;
|
||||
```
|
||||
|
||||
#### Update
|
||||
|
||||
@ -83,29 +100,39 @@ MATCH (n) WHERE NOT n.name="Roger" AND NOT n.name="Josh" RETURN n;```
|
||||
|
||||
Student "Tim" name auf "Timothy" ändern.
|
||||
|
||||
```MATCH (n :Student { name:"Tim" }) SET n.name="Timothy" RETURN n;```
|
||||
```
|
||||
MATCH (n :Student { name:"Tim" }) SET n.name="Timothy" RETURN n;
|
||||
```
|
||||
|
||||
##### Update Label
|
||||
|
||||
Give the label with name "Roger" the labels "Student" and "Teacher".
|
||||
|
||||
```MATCH (n {name:"Roger"}) SET n:Student, n:Teacher RETURN n;```
|
||||
```
|
||||
MATCH (n {name:"Roger"}) SET n:Student, n:Teacher RETURN n;
|
||||
```
|
||||
|
||||
#### Remove
|
||||
|
||||
Entfernen zweier Labels vom Node:
|
||||
|
||||
```MATCH (n :Student {name:"Roger"}) REMOVE n:Teacher, n:Student RETURN n;```
|
||||
```
|
||||
MATCH (n :Student {name:"Roger"}) REMOVE n:Teacher, n:Student RETURN n;
|
||||
```
|
||||
|
||||
Entfernen der Property address:
|
||||
|
||||
```MATCH (n :Student {name:"Roger"}) REMOVE n.address RETURN n;```
|
||||
```
|
||||
MATCH (n :Student {name:"Roger"}) REMOVE n.address RETURN n;
|
||||
```
|
||||
|
||||
#### Delete
|
||||
|
||||
Löschen eines Nodes
|
||||
|
||||
```MATCH (n :User) DELETE n RETURN n;```
|
||||
```
|
||||
MATCH (n :User) DELETE n RETURN n;
|
||||
```
|
||||
|
||||
### Relations
|
||||
|
||||
@ -121,56 +148,72 @@ Löschen eines Nodes
|
||||
|
||||
Create a Uni-Directional Relationship between Roger and Timothy called "Friend".
|
||||
|
||||
```MATCH (rog :Student {name: "Roger"}), (tim :Student {name: "Timothy"})
|
||||
```
|
||||
MATCH (rog :Student {name: "Roger"}), (tim :Student {name: "Timothy"})
|
||||
CREATE (rog)-[:FRIEND]->(tim)
|
||||
RETURN rog, tim```
|
||||
RETURN rog, tim
|
||||
```
|
||||
|
||||
Hier noch mit einer Relation Property
|
||||
|
||||
```MATCH (rog :Student {name: "Roger"}), (tim :Student {name: "Timothy"})
|
||||
```
|
||||
MATCH (rog :Student {name: "Roger"}), (tim :Student {name: "Timothy"})
|
||||
CREATE (rog)-[r :FRIEND {nickname:"Timmi"}]->(tim)
|
||||
RETURN rog, r, tim```
|
||||
RETURN rog, r, tim
|
||||
```
|
||||
|
||||
Um eine Bi-Directional Relation zu machen, muss einfach noch der umgekehrte Weg gemacht werden:
|
||||
|
||||
```MATCH (rog :Student {name: "Roger"}), (tim :Student {name: "Timothy"})
|
||||
```
|
||||
MATCH (rog :Student {name: "Roger"}), (tim :Student {name: "Timothy"})
|
||||
CREATE (rog)<-[r :FRIEND {nickname:"Rocket"}]-(tim)
|
||||
RETURN rog, r, tim```
|
||||
RETURN rog, r, tim
|
||||
```
|
||||
|
||||
Bi-Directional auf einen Chlapf:
|
||||
|
||||
```MATCH (rog :Student {name: "Roger"}), (jac :Student {name: "Jack"})
|
||||
```
|
||||
MATCH (rog :Student {name: "Roger"}), (jac :Student {name: "Jack"})
|
||||
CREATE (rog)-[r1 :FRIEND {nickname:"Rocket"}]->(jac)<-[r2 :FRIEND {nickname:"jaccc"}]-(rog)
|
||||
RETURN rog, r1, r2, jac```
|
||||
RETURN rog, r1, r2, jac
|
||||
```
|
||||
|
||||
#### Select
|
||||
|
||||
Select Relationship between 2 nodes
|
||||
|
||||
```MATCH (rog :Student {name:"Roger"})-[r]-(tim :Student {name:"Timothy"})
|
||||
RETURN rog, r, tim```
|
||||
```
|
||||
MATCH (rog :Student {name:"Roger"})-[r]-(tim :Student {name:"Timothy"})
|
||||
RETURN rog, r, tim
|
||||
```
|
||||
|
||||
#### Update
|
||||
|
||||
Update Relationship Property
|
||||
|
||||
```MATCH (:Student {name: "Roger"})<-[r:FRIEND]-(:Student {name: "Timothy"})
|
||||
```
|
||||
MATCH (:Student {name: "Roger"})<-[r:FRIEND]-(:Student {name: "Timothy"})
|
||||
SET r.nickname = "Rog"
|
||||
RETURN r```
|
||||
RETURN r
|
||||
```
|
||||
|
||||
#### Delete
|
||||
|
||||
Löschen einer Relationship. Roger will nicht mehr Freund von Timothy sein.
|
||||
|
||||
```MATCH (rog :Student {name:"Roger"})-[r:FRIEND]->(tim :Student {name:"Timothy"})
|
||||
```
|
||||
MATCH (rog :Student {name:"Roger"})-[r:FRIEND]->(tim :Student {name:"Timothy"})
|
||||
DELETE r
|
||||
RETURN rog, r, tim```
|
||||
RETURN rog, r, tim
|
||||
```
|
||||
|
||||
oder für alle Directions:
|
||||
|
||||
```MATCH (rog :Student {name:"Roger"})-[r:FRIEND]-(tim :Student {name:"Timothy"})
|
||||
```
|
||||
MATCH (rog :Student {name:"Roger"})-[r:FRIEND]-(tim :Student {name:"Timothy"})
|
||||
DELETE r
|
||||
RETURN rog, r, tim```
|
||||
RETURN rog, r, tim
|
||||
```
|
||||
|
||||
### Node and Relation
|
||||
|
||||
@ -213,6 +256,8 @@ RETURN rog, dav, type(r1), r1, type(r2), r2;
|
||||
Assuming Roger and Dave alredy exists, and they are connected by relationship `CLASSMATE`.
|
||||
`CREATE UNIQUE` Will create the relationship and the new node if it is not there (completely, relationship AND node). There is no relationship `FRIEND`, so it will create a new node `Dave` even though `Dave` already exists, but this time with the relationship `FRIEND`. So we have `Roger` and 2 times `Dave`, one with relation `CLASSMATE` and the other with relation `FRIEND`.
|
||||
|
||||
```MATCH (rog :Student {name: 'Roger'})
|
||||
```
|
||||
MATCH (rog :Student {name: 'Roger'})
|
||||
CREATE UNIQUE (rog)-[r :FRIEND]->(dav :Student {name:"Dave", age:25})
|
||||
RETURN rog, type(r), dav;```
|
||||
RETURN rog, type(r), dav;
|
||||
```
|
||||
|
||||
Loading…
Reference in New Issue
Block a user